E
Elrod
The code below is a very simplified representation of a problem I've come
across several times in a program I've been working on:
public class TestClass extends AbstractClass {
String mystery = null;
public TestClass() {
System.out.println(mystery);
}
public void abstractMethod() {
System.out.println("abstractMethod called");
this.mystery = "some value";
}
public static void main(String[] args) {
TestClass tc = new TestClass();
}
}
abstract class AbstractClass {
public AbstractClass() {
abstractMethod();
}
public abstract void abstractMethod();
}
Now everything I know about this says that the output should be:
:abstractMethod called
:some value
however, when executed, the output is
:abstractMethod called
:null
I have found that moving the "mystery" variable declaration into
"AbstractClass" or moving the call to "abstractMethod" into the "TestClass"
constructor results in the expected output, but niether of these changes can
be applied to my real-world application in any useful manner. Also, in the
case that it is a known bug, I am running java 1.4.2_04.
Any explanations or suggestions regarding this issue would be much
appreciated.
Eldon Down
across several times in a program I've been working on:
public class TestClass extends AbstractClass {
String mystery = null;
public TestClass() {
System.out.println(mystery);
}
public void abstractMethod() {
System.out.println("abstractMethod called");
this.mystery = "some value";
}
public static void main(String[] args) {
TestClass tc = new TestClass();
}
}
abstract class AbstractClass {
public AbstractClass() {
abstractMethod();
}
public abstract void abstractMethod();
}
Now everything I know about this says that the output should be:
:abstractMethod called
:some value
however, when executed, the output is
:abstractMethod called
:null
I have found that moving the "mystery" variable declaration into
"AbstractClass" or moving the call to "abstractMethod" into the "TestClass"
constructor results in the expected output, but niether of these changes can
be applied to my real-world application in any useful manner. Also, in the
case that it is a known bug, I am running java 1.4.2_04.
Any explanations or suggestions regarding this issue would be much
appreciated.
Eldon Down