Closed ashawley closed 6 years ago
Apparently, the method is marked as deprecated in Java 9:
https://docs.oracle.com/javase/10/docs/api/java/lang/Class.html#newInstance()
According to Javadoc,
This method propagates any exception thrown by the nullary constructor, including a checked exception. Use of this method effectively bypasses the compile-time exception checking that would otherwise be performed by the compiler. The Constructor.newInstance method avoids this problem by wrapping any exception thrown by the constructor in a (checked) InvocationTargetException. The call
clazz.newInstance()
can be replaced by
clazz.getDeclaredConstructor().newInstance()
Just noticed that compiling with Java 9 gives a deprecation error:
Presumably, this is because both
-deprecation
and-Xfatal-warnings
is enabled for the compiler.