Why doesn't java support unsigned ints? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why doesn't java support unsigned ints?

20th Feb 2017, 8:04 PM
Jhon
Jhon - avatar
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.
20th Feb 2017, 11:23 PM
1of3
1of3 - avatar
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.
20th Feb 2017, 8:29 PM
Fahad
Fahad - avatar
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.
21st Feb 2017, 6:20 AM
ChaoticDawg
ChaoticDawg - avatar