This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

What Diff. Between MyClassName.this and this? When use each?  RSS feed

 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Usually I see:
synchronized ( this ) {
...blah, blah...
}
But recently I saw:
synchronized ( AdminLeaseService.this )
{
...blah, bleh.....
}
Is there a difference? Is one safer than the other? Is there a point where one will work and the other won't? For example, in RMI?
[ August 23, 2002: Message edited by: Robert Paris ]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're inside an inner class, "this" refers to the current instance of the inner class. You also may need to refer to the current instance of the outer class - that's where notation like OuterClassName.this is necessary. I don't think there's any other use for it.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!