To get the t class to include, try t.getClass().getEnclosingClass() . Note that this would return null if there was no closing class.
Getting the right instance of the enclosing class is not easy, as it will rely on some details of an undocumented implementation (namely, the variable this$0 ). Here's another piece of information: In Java, how do I access an outer class when I'm not in an inner class?
Edit: I would like to emphasize once again that this$0 approach is undocumented and may be compiler dependent. Therefore, please do not rely on what is in production or in critical code.
source share