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

18.2.3: Well-typed reference conditional expressions in JLS7 are ill-typed in JLS8

    Details

      Description

      This code:

      class Test {
          void m() {
              //compiles in javac 7, but not in javac 8
              CharSequence bar = foo(true ? String.class : StringBuilder.class);
          }

          static <T> T foo(Class<T> clazz) {
              return null;
          }
      }

      is accepted by javac 7 but javac 8 generates this error message:

      Test.java:4: error: method foo in class Test cannot be applied to given types;
              CharSequence bar = foo(true ? String.class : StringBuilder.class);
                                 ^
        required: Class<T>
        found: true ? Str[...]class
        reason: inferred type does not conform to equality constraint(s)
          inferred: StringBuilder
          equality constraints(s): StringBuilder,String
        where T is a type-variable:
          T extends Object declared in method <T>foo(Class<T>)
      1 error

      Spec changes for reference conditional expressions in 8 are the cause of this issue that provokes a compatibility issue and thus should be investigated.

      http://stackoverflow.com/questions/22509488/generics-compilation-error-with-ternary-operator-in-java-8-but-not-in-java-7

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                dlsmith Dan Smith
                Reporter:
                vromero Vicente Arturo Romero Zaldivar
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: