Newbie: Equivalent to "this" keyword in Java?

W

Wes Gamble

If I am writing a method and I want to refer to the instance of the
object itself, do I use "self"? Can I use "this"? Is "this" an alias
for "self"?

Wes
 
H

Hal Fulton

Wes said:
If I am writing a method and I want to refer to the instance of the
object itself, do I use "self"? Can I use "this"? Is "this" an alias
for "self"?

It's self. There's no alias, but you can say

this = self

if you want... ;)


Hal
 
W

Wilson Bilkovich

If I am writing a method and I want to refer to the instance of the
object itself, do I use "self"? Can I use "this"? Is "this" an alias
for "self"?

It's "self", and it can also be used to differentiate between local
variables and methods, in the (very rare, usually Rails-based)
situations where there can be ambiguity.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top