Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Invalid
-
5.0M10
-
None
-
None
-
Eclipse Java Compiler 0.894_R34x, 3.4.2 release, Copyright IBM Corp 2000, 2008. All rights reserved.
WinXP/SP3
Description
Compile the following class using: javac -5 TernaryType.java
==== cut here ====
import java.util.*;
class TernaryType {
Map<String, Object> functions;
public void setFunctionsBug(Map<String, Object> funcs)
{ functions = funcs != null ? funcs : Collections.emptyMap(); } public void setFunctionsOK(Map<String, Object> funcs) {
if (funcs != null)
else
{ functions = Collections.emptyMap(); } }
}
=== cut here ===
Compiler output is:
1. ERROR in TernaryType.java (at line 8)
functions = funcs != null ? funcs : Collections.emptyMap();
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Type mismatch: cannot convert from Map<capture#1-of ? extends Object,Object> to Map<String,Object>
The two methods have exactly the same behaviour, yet only the ternary version generates an error.
Note that the Sun 1.5 and 1.6 compilers behave the same way, but it still seems like a bug to me.