Look at following code:
public class Outer {
public static void main(String[] args) throws Exception {
new Outer().greetWorld();
}
private void greetWorld() throws Exception {
System.out.println(Inner.class.newInstance());
}
public class Inner {
public Inner () {}
public String toString(){
return "HelloWorld";
}
}
}
Why is it thrown java.lang.InstantiationException
?
After all, nested class Inner
has nully constructor. Can someone explain it?
Aucun commentaire:
Enregistrer un commentaire