• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How does this work? sychronized([Classname].this) {...

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I'm looking over some code and I'm not sure what the following bit does:

What object or instantiation of ClassA does ClassA.this refer to?
Thank you ahead of time for your help.
Spencer
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An instance of a non-static nested class -- a so-called inner class like ClassB -- always has an enclosing instance of the outer class. An instance of ClassB can't be created without associating it, permanently, with an instance of ClassA (try it.) It is this instance that "ClassA.this" refers to.
 
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is actually a semantic issue, so I'm moving it to JIG Intermediate.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Spencer - this has nothing to do with your original question, so just ignore it unless you're interested. But for EFH:
[EFH]: An instance of a non-static nested class -- a so-called inner class like ClassB -- always has an enclosing instance of the outer class.
Not quite. See JLS 15.9.2 It's possible to define an inner class in a static context, such as inside a static method, static variable initializer, or class initializer. In such cases there's no accessible outer instance. And while it may seem as though a nested class created in a static context should be the same as an implicitly static class, and therefore not an inner class - this is not the case. The rules for "implicitly static" (e.g. something declared as a member of an interface) are not the name as the rules for "declared in a static context". One differene is that an implicilty static class could declare a static member, but an inner class declared in a static context may not:

[ March 04, 2004: Message edited by: Jim Yingst ]
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jim Yingst:

Not quite.


All right, I give up. I'm off to read the JLS on inner classes.
The funny thing is that when I typed my response above, I included something along the lines of "Of course, now Jim is going to explain to us where I got this wrong." But then I erased it.
 
You can't expect to wield supreme executive power just because
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic