So, I have an object which is an instance of an inner class. I need to find
reflectively the
instance of the outer class which is associated with it.
I might not be seeing the wood for the trees here but I can't see how. Effectively I need an object equivalent of "Class.getDeclaringClass()"
An example to help explain, if required:
public class FindOuterObject
{
public static void main(String[] args)
{
new FindOuterObject();
}
private FindOuterObject()
{
InnerObject i = new InnerObject();
Object o = findOuterObject(i);
System.out.println((o == this) ? "Worked" : "Failed");
}
private static Object findOuterObject(Object innerObject)
{
// Need to fill in this method to work for any object passed in
return null;
}
public class InnerObject
{
}
}