Unsigned short in Java

maiky picture maiky · Dec 3, 2009 · Viewed 98.7k times · Source

How can I declare an unsigned short value in Java?

Answer

Jon Skeet picture Jon Skeet · Dec 3, 2009

You can't, really. Java doesn't have any unsigned data types, except char.

Admittedly you could use char - it's a 16-bit unsigned type - but that would be horrible in my view, as char is clearly meant to be for text: when code uses char, I expect it to be using it for UTF-16 code units representing text that's interesting to the program, not arbitrary unsigned 16-bit integers with no relationship to text.