With reflection you cannot change the class modifiers but you can create objects of the specified class and invoke its methods.
You can get instance the class from the enclosing class with the method getDeclaredClasses()
, and then modify the contructor and instantiate the object:
Class a = A.class;
Class subs[] = a.getDeclaredClasses();
Object o = null;
for (Class cls: subs) {
if(cls.getCanonicalName().equals("A.B")){
for (Constructor ct: cls.getDeclaredConstructors()) {
ct.setAccessible(true);
o = ct.newInstance(new Inner());
// o is an instance of B
// you can get public and private method and invoke them
for (Method m: o.getClass().getDeclaredMethods())
if(m.getName().equals("....")){
m.setAccessible(true);
m.invoke(o, ....));
}
}
}
}
Instead of the for loop you could get methods by name and list of parameters.