View Single Post
  #3 (permalink)  
Old July 3rd, 2006, 01:41 AM
panacea panacea is offline
Friend of Wrox
Join Date: Jan 2006
Location: San Francisco, CA, USA.
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts

The implementation is actually a mix between your two approaches. The compiler compiles references to static variables and methods into special bytecodes that specifically denote that the reference or call is static. Then when the JVM executes the bytecodes, it knows to look up the static variables or methods in the class definition, rather than in an object instantiation.

More detail can be found here: (Definition of the bytecode for retrieving a static class member.)

After reading up on this subject, I'm still confused how different classloaders fit into the situation. Does a class loaded by two different classloaders have two instances of static member variables? How does the getstatic bytecode know which classloaders to use -- does it always use the system classloader? If anyone else has information on this, I'd love to hear it.

Jon Emerson