Here is a single line that should work in the Java 5+ JVM and does not add any additional import data to your code:
new Object(){}.getClass().getEnclosingClass()
Creates an anonymous inner class, gets its Class object, and then gets its instance of the wrapper class, which should be your class. For instance:
public class HelloClass { static final Class<?> THIS_CLASS = new Object(){}.getClass().getEnclosingClass(); public static void main(String[] args) { System.out.println(THIS_CLASS);
In the context of your question:
static X s_x = new X(new Object(){}.getClass().getEnclosingClass());
matts source share