Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java ternary operator

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.

like image 357
Dónal Avatar asked Dec 29 '22 11:12

Dónal


1 Answers

This was a bug in 1.4 and has been fixed according bugreport 5080917.

Evaluation This is a bug.

xxxxx@xxxxx 2004-07-30

like image 113
BalusC Avatar answered Dec 31 '22 00:12

BalusC