Campbell Ritchie wrote: It also doesn't tell you that you oughtn't to use newInstance() any more.
Campbell Ritchie wrote:
So tried your code and didn't get any exceptions.
Code used copied'n'pasted from above post unchanged. Insert “System.out.println(o);” after line 10 in first class, and I get this instead:-Campbell's Java12/Linux/x64 wrote:[critchie@...~]$ pluma NewInstanceTest2.java&
[1] 31972
[critchie@... ~]$ javac NewInstanceTest2.java
Note: NewInstanceTest2.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
[critchie@... ~]$ java NewInstanceTest2
Fri Apr 26 10:12:58 BST 2019
Fri Apr 26 10:12:58 BST 2019
[critchie@...~]$ pluma NewInstanceTest1.java&
[2] 32147
[critchie@... ~]$ javac NewInstanceTest1.java
Note: NewInstanceTest1.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
[2]+ Done pluma NewInstanceTest1.java
[critchie@... ~]$ java NewInstanceTest1
woof!
[critchie@... ~]$
Note typical output from un‑overridden toString() method.. . . java NewInstanceTest1
woof!
NewInstanceTest1$Dog@4d7e1886
JEP 181 wrote:
A further consequence of the lack of JVM support for private access within a nest, is that core reflection also denies access.
A reflective method invocation (using java.lang.reflect.Method.invoke) from one nestmate to another throws IllegalAccessError (unless access control has been disabled).
This is surprising given that reflective invocations should behave the same as source level invocations.
Stephan van Hulst wrote:The error message tells you exactly why it can't create an instance of NewInstanceTest1$Dog: It has the private access modifier.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |