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

spec changes for reference conditional expressions

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 8, 9
    • Fix Version/s: None
    • Component/s: specification
    • Labels:
      None

      Description

      This code:

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

      compiles fine with javac 7 but for 8 it fails with 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

      This is a compatibility issue due to the current spec that should be investigated.

      originally reported in SO: 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:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: