S
Stanimir Stamenkov
I've found couple of threads [1] discussing the exact same problem, but
I've wondered if there are some normative references governing the
change in the behavior I'm seeing between classes compiled with -target
1.4 and prior versions?
If I compile the following example with -target 1.4 and run it, I don't
get error, but If I compile it with no -target specified (or version <
1.4, using J2SDK 1.4.2) I get NullPointerException because of the
"missing" EnclosingInstanceTest instance at the given time. When I
compile with JDK 1.5 I don't get error because the default target seems
to be >= 1.4.
-----EnclosingInstanceTest.java
public class EnclosingInstanceTest {
public static void main(String[] args) {
EnclosingInstanceTest obj = new EnclosingInstanceTest();
System.out.println("Start...");
obj.doTest();
}
void doTest() {
Whatever ever = new Whatever() {
/* init */ {
System.out.println("(2) Enclosing instance: "
+ EnclosingInstanceTest.this);
}
void doSomething() {
System.out.println("(*) Enclosing instance: "
+ EnclosingInstanceTest.this);
testInstance();
}
};
ever.doSomething();
}
void testInstance() {
System.out.println("O.k.");
}
}
abstract class Whatever {
Whatever() {
System.out.println("(1) Super class init");
// XXX: Uncomment the following line to test
doSomething();
}
abstract void doSomething();
}
-----EnclosingInstanceTest.java--
[1] NullPointerException accessing instance member of enclosing
instance
<http://groups.google.com/group/comp...read/thread/81eeb5e4e0d53a33/3aafa2d47d87780a>,
Getting a null "this"
<http://groups.google.com/group/comp...read/thread/dd32223ae8a25867/c2c452392f0c7d70>
I've wondered if there are some normative references governing the
change in the behavior I'm seeing between classes compiled with -target
1.4 and prior versions?
If I compile the following example with -target 1.4 and run it, I don't
get error, but If I compile it with no -target specified (or version <
1.4, using J2SDK 1.4.2) I get NullPointerException because of the
"missing" EnclosingInstanceTest instance at the given time. When I
compile with JDK 1.5 I don't get error because the default target seems
to be >= 1.4.
-----EnclosingInstanceTest.java
public class EnclosingInstanceTest {
public static void main(String[] args) {
EnclosingInstanceTest obj = new EnclosingInstanceTest();
System.out.println("Start...");
obj.doTest();
}
void doTest() {
Whatever ever = new Whatever() {
/* init */ {
System.out.println("(2) Enclosing instance: "
+ EnclosingInstanceTest.this);
}
void doSomething() {
System.out.println("(*) Enclosing instance: "
+ EnclosingInstanceTest.this);
testInstance();
}
};
ever.doSomething();
}
void testInstance() {
System.out.println("O.k.");
}
}
abstract class Whatever {
Whatever() {
System.out.println("(1) Super class init");
// XXX: Uncomment the following line to test
doSomething();
}
abstract void doSomething();
}
-----EnclosingInstanceTest.java--
[1] NullPointerException accessing instance member of enclosing
instance
<http://groups.google.com/group/comp...read/thread/81eeb5e4e0d53a33/3aafa2d47d87780a>,
Getting a null "this"
<http://groups.google.com/group/comp...read/thread/dd32223ae8a25867/c2c452392f0c7d70>