...
This noncompliant code example prints 100 as the size of the HashSet
rather than the expected result (some value between 0 and 50). The combination of values of types short
and int
in the second argument of the conditional expression (the operation i-1
) causes the result to be an int
, as specified by the normal integer promotion rules. Consequently, the Short
object in the third argument is autounboxed unboxed into a short
, which is then promoted into an int
. The result of the conditional expression is then autoboxed into an object of type Integer
. Because the HashSet
contains only values of type Short
, the call to HashSet.remove()
has no effect.
...