Is it possible to instantiate a private inner class from another class using Java reflection. For example if I took this code
public class Main {
public static void main(String[] args) {}
}
class OtherClass {
private class Test {}
}
is it possible to instantiate and gain access to Test from the main method in the class main.
When using reflection, you’ll find constructors of that inner class taking an instance of the outer class as an additional argument (always the first) .
See these questions for related information:
Instantiating inner class
How can I instantiate a member class through reflection on Android
In Java, how do I access the outer class when I'm not in the inner class?
Example: