JDK-7189915 : Conditional assignment in combination with diamond operator gives complier error
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2012-08-08
  • Updated: 2012-09-06
  • Resolved: 2012-08-08
Related Reports
Duplicate :  
Description
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.