There are several ways this can be done. The following class Outer, which contains the public static nested class Inner, will be used to illustrate two possible ways:
public class Outer {
public static class Inner {
public int y;
public Inner() {
y = 1;
}
public Inner(int y) {
this.y = y;
}
}
public static Inner makeInner() {
return new Inner();
}
}
- Add a public static method that returns a new instance of the inner class.
in = Outer.makeInner();
in.getClass().toString()
ans =
class Outer$Inner
- Use java.lang.Class.getClasses().
out = Outer();
oc = out.getClass();
oc_public = oc.getClasses();
inner_class = oc_public(1);
in1 = inner_class.newInstance();
types = javaArray('java.lang.Class',1);
types(1) = java.lang.Integer.TYPE;
in2 = inner_class.getConstructor(types).newInstance(int32(5));