JDK-8283146 : Example in 4.3.1 uses deprecated API
  • Type: Enhancement
  • Component: specification
  • Sub-Component: language
  • Affected Version: 19
  • Priority: P4
  • Status: New
  • Resolution: Unresolved
  • Submitted: 2022-03-15
  • Updated: 2022-03-15
Related Reports
Relates :  
Relates :  
Description
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 by JDK-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);
        }