Re: Why all the max length constraints?

From: Marshall <marshall.spight_at_gmail.com>
Date: 30 May 2006 16:09:39 -0700
Message-ID: <1149030578.632384.30320_at_u72g2000cwu.googlegroups.com>


Bob Badour wrote:
> Marshall wrote:
>
> > David Cressey wrote:
> >
> >>I thought Marshall said that Java strings were limited to a few gigabytes.
> >>I that "almost unlimited"?
> >
> > OT: Java's String object is a wrapper for an array of char. Java
> > arrays are indexed by an int, which is by definition (by the *Java*
> > definition) a 32 bit signed integer. Because of this, arrays are
> > limited to 2^32-1 length, which means String objects have
> > the same limit on length.
>
> Do they really use the negative range?

[Not 100% sure I understand the question; taking my best shot. Feel free to correct.]

Java primitive integer types are all signed; there are no unsigned primitive types. (Technically, char is an unsigned primitive, though.) I believe the intent was simplification and the reduction in language "gotchas" associated with signed-to-unsigned conversion and vice versa, etc.

Because there is no unsigned primitive integer type, arrays are necessarily indexed by a signed integer type, reducing the max size of arrays by (approximately) a factor of two. Array indexes still start at 0, though; attempts to use the negative part of the range unconditionally throw ArrayIndexOutOfBoundsException.

(Java has the primitive long, and also BigInteger, but you can't use them as array indexes.)

All in all, I would judge the effort to eliminate the signed/unsigned split as a noble experiment that failed.

Marshall Received on Wed May 31 2006 - 01:09:39 CEST

Original text of this message