A DESCRIPTION OF THE REQUEST :
Currently, it is impossible to create an anonymous class that doesn't reference its outer class through some variable like this$0. I would like to see this possible:
new static A() { ... }
which would work just like:
new A() { ... }
except that the anonymous inner class could not access the enclosing class.
JUSTIFICATION :
The static anonymous inner class would be more efficient to construct for classes which don't access their outer defining class AND the static anonymous inner class would not reference the outer class... which is a huge advantage in restricting reachability-sensitive technologies like serialization.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Creates a static anonymous class that does not permit access to enclosing classes through this pointers.
ACTUAL -
Feature does not exist.
Currently, it is impossible to create an anonymous class that doesn't reference its outer class through some variable like this$0. I would like to see this possible:
new static A() { ... }
which would work just like:
new A() { ... }
except that the anonymous inner class could not access the enclosing class.
JUSTIFICATION :
The static anonymous inner class would be more efficient to construct for classes which don't access their outer defining class AND the static anonymous inner class would not reference the outer class... which is a huge advantage in restricting reachability-sensitive technologies like serialization.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Creates a static anonymous class that does not permit access to enclosing classes through this pointers.
ACTUAL -
Feature does not exist.
- relates to
-
JDK-8271623 Omit enclosing instance fields from inner classes that don't use it
-
- Resolved
-