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

Conditional assignment in combination with diamond operator gives complier error

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 7
    • tools
    • x86
    • linux

      FULL PRODUCT VERSION :
      jdk1.7.0_05

      ADDITIONAL OS VERSION INFORMATION :
      3.1.10-1.16-desktop #1 SMP PREEMPT Wed Jun 27 05:21:40 UTC 2012 (d016078) x86_64 x86_64 x86_64 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      Compiler failed in code line using a conditional assignment with the diamond operator.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile test code below.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Compile without error.
      ACTUAL -
      Compiler error:
      error: incompatible types
                                  List<String> list = true ? new ArrayList<>() : null;
        required: List<String>
        found: ArrayList<Object>

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
       List<String> list = true ? new ArrayList<>() : null;
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Avoid diamond operator or conditional assignment.

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: