Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8283146

Example in 4.3.1 uses deprecated API

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 18
    • specification

      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);
              }

            abuckley Alex Buckley
            darcy Joe Darcy
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: