-
Enhancement
-
Resolution: Duplicate
-
P4
-
None
-
18
Example 4.3.1-1. Object Creation contains the code
try {
p = (Point)Class.forName("Point").newInstance();
} catch (Exception e) {
System.out.println(e);
}
Class.newInstance was deprecated byJDK-6850612 in JDK 9 since it can throw undeclared checked exceptions. The recommended replacement code is:
try {
p = (Point)Class.forName("Point").getDeclaredConstructor().newInstance();
} catch (ReflectiveOperationException e) {
System.out.println(e);
}
try {
p = (Point)Class.forName("Point").newInstance();
} catch (Exception e) {
System.out.println(e);
}
Class.newInstance was deprecated by
try {
p = (Point)Class.forName("Point").getDeclaredConstructor().newInstance();
} catch (ReflectiveOperationException e) {
System.out.println(e);
}
- duplicates
-
JDK-8280602 4.3.1: Avoid use of newInstance when it is terminally deprecated
- Open
- relates to
-
JDK-6850612 Deprecate Class.newInstance since it violates the checked exception language contract
- Resolved
-
JDK-8283144 4.2.3: Improve wording w.r.t. positive and negative zero
- Resolved