-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
1.1.7
-
generic
-
generic
Name: tb29552 Date: 10/29/98
/*
Consider the following example
(based on real code):
The output when B.main() is run is "B".
The expected output is "A".
The B object returned by getA in main's A object
cannot access its enclosing A instance. The
expression "A.this" which should refer to the
enclosing class according to the Inner Class
Specification is interpreted as "this".
*/
class A {
public String toString() {
return "A";
}
A getA() {
return new A ();
}
void test() {
}
}
class B extends A {
public String toString() {
return "B";
}
public static void main(String[] args) {
new A () {
A getA() {
return new B () {
void test() {
System.out.println(A.this.toString());
}
};
}
}.getA().test();
}
}
(Review ID: 41518)
======================================================================
- relates to
-
JDK-4102393 Inside an anonymous inner class, how can this==Enclosing.this? (Modena:ciner066)
- Closed
-
JDK-4133457 anonymous this refers to super instance instead of enclosing instance
- Closed