Contents    Page-10    Prev    Next    Page+10    Index   

Are Basic Types Objects?

There is an advantage of consistency if basic types such as integer and real are objects. However:

Lisp codes small integers as special pointer values, eliminating the need to box small integers; reals are boxed.

Java caches and reuses small Integer values from -128 to 127.

An alternative is to have both boxed and unboxed numbers; this improves performance but results in an inconsistent type system. Java uses this method; as a result, a generic method that does comparison may have to be recoded 6 times because of type inconsistencies.