I have half a dozen classes which all extend the same abstract class. The abstract class has a static variable pointing to some JNI code that I only want to load once per in
I have a similar problem. Looks like Java can't isolate static members (attributes). I ended up adding an abstract method instead of the attribute:
public abstract class Abs {
public void printX() {
System.out.println("For " + this.getClass() + " x=" + getX());
}
protected abstract Integer getX();
}
public class A extends Abs {
protected static Integer x = 1;
@Override
protected Integer getX() {
return x;
}
}
public class B extends Abs {
protected static Integer x = 2;
@Override
protected Integer getX() {
return x;
}
}
public class test {
public static void main(String args[]) {
Abs a = new A();
a.printX();
Abs b = new B();
b.printX();
Abs c = new A();
a.printX();
b.printX();
c.printX();
}
}