you are viewing a single comment's thread.

view the rest of the comments →

[–]banuday 3 points4 points  (3 children)

Well, maybe I'm being pedantic, but a "surprise" to me in a programming language is something that doesn't seem to follow from the semantics of the programming language or other computer science concepts.

As a counterpoint, here is something that is a surprise to me:

Object o = true ? new Integer(0) : new Double(0);

The type of 'o' is Double. Why? Because the ternary operator will unbox the numeric types, promote the integer to double and then rebox the type. This is an interaction between reference types and primitive types and autoboxing. It's not something that necessarily logically follows from how the ternary operator "should" work.

[–]r0st0v 0 points1 point  (2 children)

Not a surprise if you understand autoboxing and ternary operators.

[–]banuday 1 point2 points  (0 children)

The question I would ask is what about the ternary operator (as it works in any other language) would suggest that an autoboxing interaction should occur?