Good afternoon. There is an instance of some inner class that has a constructor with a parameter . I.e:

class A{ ... class B{ B(int i){ } } ... class C{ C(int i){ } } ... } 

How to use reflection to create another instance of this class?

    1 answer 1

     Class<?> enclosingClass = Class.forName("A"); Object enclosingInstance = enclosingClass.newInstance(); Class<?> innerClass = Class.forName("A$B"); Constructor<?> ctor = innerClass.getDeclaredConstructor(enclosingClass, int.class); Object innerInstance = ctor.newInstance(enclosingInstance, 42);