Conditional operator applies assignment conversion

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P1
    • 5.0
    • Affects Version/s: 5.0
    • Component/s: tools
    • b60
    • generic
    • generic

      Currently, javac accepts uses of the conditional operator which are in violation of the Java Language Specification:

      String[] sa = null;
      List<String> ls = (sa == null) ? Arrays.asList(sa) : Collections.emptyList();

      According to the spec, the type of the conditional operator should be lub(List<String>, List<Object>) = List<?> why the assignment is illegal. However, javac compiles this example without any errors or warnings.

            Assignee:
            Peter Ahe
            Reporter:
            Peter Ahe
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: