-1

Simple question, I know what this does in Java but is this considered an instance variable belonging to the class?

lxcky
  • 1,668
  • 2
  • 13
  • 26
Code Doggo
  • 2,146
  • 6
  • 33
  • 58
  • Alright thank you for showing me the existing question. I apologize for not noticing it earlier before posting this question. You may close this question. @Jigar Joshi – Code Doggo Aug 30 '14 at 01:32
  • You may be able to delete it if you wish. It is already closed. – Sotirios Delimanolis Aug 30 '14 at 01:33
  • It is a duplicate question, but not a dumb one. In Scala, they're still evolving what "this" can do. (e.g. pattern matching) – som-snytt Aug 30 '14 at 01:34
  • The way I would define `this` is that it's an immutable reference value (as opposed to a mutable reference variable) which refers to the current object instance. – Hot Licks Aug 30 '14 at 02:01

1 Answers1

0

this is not an instance variable belonging to the class. this is a reference to an instance of the current class.

lxcky
  • 1,668
  • 2
  • 13
  • 26
  • 1
    `this` is a reference, and a reference is not an instance. – Hot Licks Aug 30 '14 at 01:59
  • Actually, the JLS says this: *"When used as a primary expression, the keyword this denotes a value that is a reference to the object ..."*. Hence `this` is an expression, whose value is a reference. – Stephen C Aug 30 '14 at 03:47
  • @StephenC *Non sequitur.* A literal can also be used as a primary expression: that doesn't mean it *is* an expression. – user207421 Aug 30 '14 at 23:57
  • @EJP - OK, "hence" is too strong. But in the real point is that `this` is an expression that evaluates to a reference. It is not a reference. (Just like a variable name is a primary that evaluates to a value ... not the value itself.) – Stephen C Aug 31 '14 at 01:14