C
colibri
I have posted this message in the Sun Developer Network on the Java
Programming Forum with little feedback. The post is
http://forum.java.sun.com/thread.jspa?messageID=9882939
I am trying here with the hope of receiving some help here.
I have a class B that is a subclass of class A. Class A has a
protected static field. Under windows, reading this field from a
static method of class B yields the desired results, meaning that the
field contains the value assigned before somewhere else.
Running the same code under Linux, the field sometimes contains the
correct value and sometimes the value assigned at declaration time:
It goes like this:
package packageA;
public class A
{
protected static Collection items = new ArrayList();
public static void addItem(Object item)
{
items.add(item);
}
} // class A
package packageB;
public class B
extends A
{
public static void methodA()
{
System.out.println(A.modules.size());
System.out.println(B.modules.getSize());
System.out.println(modules.size());
}
} // class B
import packageA.A;
import packageB.B;
public static void void main(String[] args)
{
Object item;
item = new String("");
A.addItem(item);
B.method();
} // main(String[])
What is even more strange, is that if I run the above example in a new
project, the results are as expected. But if I run this other project
I am working on, the results are as if B.items is independent of
A.items. Even if I implement a method A.getItems() and call it from
B.method() to store the items in a variable local to B.method(), the
result is an empty ArrayList.
My first attempt was to place the A and B classes in the same package,
and since the results were as expected, I changed each class to its
own package and the Main class to an independent package. The results
do not change in this scenario.
Your help is appreciated.
The environment is:
Netbeans 5.5
JDK 1.6.0
xubuntu (Linux 2.6.20-16-generic i686 GNU/Linux
JC
Programming Forum with little feedback. The post is
http://forum.java.sun.com/thread.jspa?messageID=9882939
I am trying here with the hope of receiving some help here.
I have a class B that is a subclass of class A. Class A has a
protected static field. Under windows, reading this field from a
static method of class B yields the desired results, meaning that the
field contains the value assigned before somewhere else.
Running the same code under Linux, the field sometimes contains the
correct value and sometimes the value assigned at declaration time:
It goes like this:
package packageA;
public class A
{
protected static Collection items = new ArrayList();
public static void addItem(Object item)
{
items.add(item);
}
} // class A
package packageB;
public class B
extends A
{
public static void methodA()
{
System.out.println(A.modules.size());
System.out.println(B.modules.getSize());
System.out.println(modules.size());
}
} // class B
import packageA.A;
import packageB.B;
public static void void main(String[] args)
{
Object item;
item = new String("");
A.addItem(item);
B.method();
} // main(String[])
What is even more strange, is that if I run the above example in a new
project, the results are as expected. But if I run this other project
I am working on, the results are as if B.items is independent of
A.items. Even if I implement a method A.getItems() and call it from
B.method() to store the items in a variable local to B.method(), the
result is an empty ArrayList.
My first attempt was to place the A and B classes in the same package,
and since the results were as expected, I changed each class to its
own package and the Main class to an independent package. The results
do not change in this scenario.
Your help is appreciated.
The environment is:
Netbeans 5.5
JDK 1.6.0
xubuntu (Linux 2.6.20-16-generic i686 GNU/Linux
JC