File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes What Diff. Between MyClassName.this and this? When use each? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What Diff. Between MyClassName.this and this? When use each?" Watch "What Diff. Between MyClassName.this and this? When use each?" New topic
Author

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

Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
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

Joined: Jan 30, 2000
Posts: 18671
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.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What Diff. Between MyClassName.this and this? When use each?