Name: bsC130419 Date: 08/08/2001 java version "1.3.1" Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24) Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode) While current Java syntax allows access to the outer containing object of the 'this' object of a non-static inner class type (e.g., 'Outer.this'), there is no syntax for accessing the outer object of an inner object other than 'this'. For example: class Outer // Outer class { int compare(Outer o) {...} class Inner // Non-static inner class { int compare(Inner i) { // Compare the outer objects of 'this' and 'i' return Outer.compare(Outer.this, i.???); // [A] } } } With the present language syntax, I am forced to use a helper method in the inner class: class Inner { Outer thisOuter(Inner) { return this.Outer; // [B] } ... } This hack allows me to write the method of the inner class that needs to access the outer object of a non-this object: int compare(Inner i) { // Compare the outer objects of 'this' and 'i' return Outer.compare(Outer.this, i.thisOuter()); // [C] } But the overhead of a helper function should not be necessary. I feel that the Java language syntax should be extended to allow expressions of the form: object.Classname.this (or something like it) which retrieves the outer class object (of type 'Classname') of object 'object', which is of some non-static inner class type. This syntax is very close in spirit to the existing syntax: Classname.this -- (Review ID: 129580) ======================================================================
|