This question already has an answer here:
I always thought that this:
Object o1 = true ? new Integer(1) : new Double(2.0);
is the same as doing this:
Object o2;
if (true)
o2 = new Integer(1);
else
o2 = new Double(2.0);
But as output I got 1.0 for the first example and 1 for the second one.
Why they give me different results? And why I've got a Double result in the first place?
Aucun commentaire:
Enregistrer un commentaire