Re: Static Variables and JAR Files
On Mar 4, 7:06 am, Roedy Green <see_webs...@mindprod.com.invalid>
wrote:
On Mon, 3 Mar 2008 11:23:07 -0800 (PST), Jason Cavett
<jason.cav...@gmail.com> wrote, quoted or indirectly quoted someone
who said :
BaseClass has a static object (ObjectX). Now, normally, this static
object is static across all of the subclasses. However...
Please post some example code. There is no such thing as a "static
object". If you want a singleton, it will have to be a static
reference in only one class.
--
Roedy Green Canadian Mind Products
The Java Glossaryhttp://mindprod.com
Yeah, I realize that I misspoke. Thank you for the correction. I,
instead, have a static member variable that refers to an object.
Anyway...the example code is pretty simple.
class Base {
protected static String someInfo = null;
public Base() {
// instantiate
}
}
class Child extends Base {
public Child() {
if(Base.someInfo == null) {
someInfo = new String("String Here");
}
}
}
I have a couple other children that also extend base and, if someInfo
is null, they give the String their own value. However, when I use
this 3rd party application to load up the different children classes,
someInfo is always null upon load and will be set with the string
specific to that child.
After doing some testing, I printed out the information of the String
and it is NOT the same String. (AKA - Different classloaders are
probably being used to load up the children.) What I'm wondering is
whether or not it is possible to stop this from happening. AKA -
someInfo will refer to the same object across all classloaders.
Thanks