How can I return the object of a private inner class
public class MainClass{
public InnerClass getObj(){
return this.new InnerClass()
}
private class InnerClass{
InnerClass(){
}
}
}
-------------
MainClass mc = new MainClass();
mc.getObj(); // assume I am not holding it anywhere.
The above code is giving a null pointer exception, when I checked with the try-catch blocks.
Also, when tried in debug mode, its says ‘ClassNotFoundException‘
But I can see the class file generated as MainClass$InnerClass.class
Hmmm, I’m not having that same problem. Here’s my modified version of your code:
The result of this code is: