Can someone explain why this code?
Collection c = (5 == 5) ? new ArrayList() : new HashSet();
produces the following compiler error:
Incompatible conditional operand types ArrayList and HashSet
For reasons that I don't understand, the following fixes the problem
Collection c = (5 == 5) ? (Collection) new ArrayList() : new HashSet();
I'm using Java 1.4.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…