1
vringar
8y

Why tf does Java return an integer when you add 2 shorts

Comments
  • 3
    Because the result of the shorts you're adding might be too big to be contained by a short.
  • 3
    @MaxMayo In that case it would have to return a long when adding two integers, and what would it return when adding two longs?

    Sounds inconsistent to me. Why not just let it overflow?
  • 1
    It always returns integer with any math operation you do. And it sucks if you specs tell you to exclusively use short.
    @deadlyRants exactly, but who are we to question the mighty oracle overlords
Add Comment