poohbar
01/09/2019, 6:22 PMhudsonb
01/09/2019, 6:46 PMArtem Golovko
01/10/2019, 5:50 AMConstructor<Foo> constructor= (Constructor<Foo>) Foo.class.getDeclaredConstructors()[0];
constructor.setAccessible(true);
obj = constructor.newInstance("foo");
But in you case if you want define an internal class in the parent class, I think, you should use private class Child()
and you can create Child class everywhere in your Parent class, but you can't create Child outside the Parent class, because it's private.
But according for your code whatever you want it's hide constructor of the class. And you can use something like this.
class Child private constructor () {
companion object {
operator fun invoke(): Child {
return Child()
}
}
}
class Parent() {
companion object {
operator fun foo = Child()
}
}