Re: Static Variables and JAR Files
 
Jason Cavett wrote:
These JAR files (AnotherPackage and EvenAnotherPackage) are being read
in by a separate tool.  When ExtendedClassA and ExtendedClassB are
used within the context of this tool, ObjectX is instantiated twice
and has two separate values.  As far as I can tell, the tool runs
ExtendedClassA and ExtendedClassB within the same JVM, so I am unsure
of what is going on.
Obviously, when you make a new class via inheritance, it gets it's own 
copy of the static variable.  So there will be one static for the parent 
class, and one for the child class.  The static is a "class variable" 
and since there are two classes (parent and child) there are two static 
variables.
There could be other things going on.  The tool may be using 
ClassLoaders to load the jar files.  When a separate ClassLoader is 
used, classes loaded under separate ClassLoaders are separate classes. 
Even if there was no inheritance involved, there may still be two 
separate ObjectX and two copies of the static variable.  If this is the 
case, there will also be two copies of the class object itself (it gets 
loaded twice, to separate memory areas) which is the root cause of this 
particular static issue.
You may need to look at the documentation of the tool you are using, and 
decide how you need to correctly deal with this situation.  Just 
curious: what tool are we talking about here?  Like maybe a web container?
There could be other issues too.  Fire up the debugger, read the source 
code, decompile some tool code, or bug the manufacturer support site. 
Stuff happens.