+ 1
Why doesn't java support unsigned ints?
3 Answers
+ 1
Considering that negative input is probably the most common reason for IllegalArgumentException, one has to wonder.
Fahad, that can we can handle doesn't mean we should. The more errors won't get past the compiler, the better.
0
We can do the work without them and its good as it gives us the ability to type signed or unsigned value and as per requirement removing the sign through math library with abs function so i think its useless to have extra variable type.
0
In Java 8 and later you can use the Integer class and it's unsigned static methods, such as compareUnsigned, toUnsignedLong, divideUnsigned, remainderUnsigned, parseUnsignedInt, toUnsignedString.
http://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html
Or you can use a long as a property in your class and then use your getters and setters to control the legal values that it will accept and throw an error if it is out of range if desired.