I know that when I read the answer to this I will see that I have overlooked something that was under my eyes. But I have spent the last 30 minutes trying to figure it out m
The problem with autounboxing null
values can be really annoying. In your example it's a combination of ternary operator result type inferring and autounboxing (the JLS should be consulted why it behaves like that)
But generally, you should try to avoid using wrapper types. Use int
instead of Integer
. If you need a special value meaning "no result", then you can use Integer.MAX_VALUE
for example.