|
Java™ by example!
|
|
|
How do I instantiate an inner class using reflection?
A static inner class can be instantiated without the need of an instance of the outer class. Main.java:
You need an instance of the outer class to instantiate a non-static inner class. Just specify it before the new operator. An inner class will have an implicit constructor taking a parameter that takes a parameter to the enclosing object. So you need to create a Constructor object and invoke it providing it with the instance of the outer object. Main.java:
Further Information
Author of answer: Joris Van den Bogaert
Comments to this answer are only viewable by members. Login or become a member!
|
|
|
|
|