Alex Rivera | Logout

Is Java's lack of unsigned primitive types a characteristic of Java the platform or Java the language?

Asked 2011-12-01T17:27:48.880
10

There are questions about why Java doesn't support unsigned types and a few questions about dealing with unsigned types. I did some searching, and it appears that Scala also doesn't support unsigned data types. Is the limition in the language design of Java and Scala, in the generated bytecode, or is it in the JVM itself? Could there be some language that runs on the JVM and is otherwise identical to Java (or Scala), yet supports unsigned primitive data types?

Edit
Report

1 Answer

2

Although unsigned type might be emulated at the bytecode level there are some drawbacks with that:

  • Performance: You would need several bytecode operations for each simple arithmetic operation. The performance of code using the emulated unsigned types would be two or three times worse than code using signed types.

  • Compatibility: Most languages running on a JVM try very hard to be compatible with the huge amount of Java code out there. This of course would be spoiled immediately when additional types are introduced or when some variables with "known" types have to handled differently.

In the light of this the benefits for unsigned types are IMHO negligible.

answered 2011-12-01T18:06:03.370

Your Answer