I have a puzzle involving inner cl***** that look like this:
public class TP {
public final String tpName;
public TP(String name) { tpName = name; }
public TCP tpc = new TCP(name+".tcp");
public DataObject getListed(int index) {...}
public class TPC { // non-static inner class
public final String tpcName;
public TPC(String name) { tpcName = name; }
public TPCR tpcr = new TPCR(name+".tpcr");
public DataObject getDataObject(int index) {
return getListed(index);
}
public class TPCR { // non-static inner class
public final String tpcrName;
public TPCP(String name) { tpcrName = name; }
public void display(int n) {
DataObject d = getDataObject(n);
if(d != null)
System.out.println(d.toString());
} // end isListed()
} // end display()
} // end inner class TPCR
} // end inner class TPC
} // end class TP
I have two TP objects: tp_1 and tp_2, and each has one
TCP object, and each TCP object has one TPCR object.
When calling 'tpcr.display(n) from the context of tp_2', I
find that the function executes in the context of tp_2 in
the call to 'getDataObject(n)', but it executes in the context
of tp_1 in the nested call to 'getListed(n)'.
Upon return from the call stack, however, the context of
tp_2 has been restored.
Each object has a String 'xName' member, and I have determined
context by examining the name of the outermost container.
Perhaps a detailed examination of the call stack would show
something different, but this apparent switch of context is
puzzling and disturbing.
I am using version 5.0.0.951 of the CW IDE and the included
CW Java compiler. Has any similar problem with inner cl*****
been re****ted?
Thanks in advance.
Jonathan Wilcox


|