> From: Attila Szegedi [mailto:[EMAIL PROTECTED]]
>
> The other infinitely lame thing in Sun's JDK collections
> implementation is
> an explicit call to method named RangeCheck() in all
> ArrayList accessors.
> Basically, it looks like this
>
> public Object get(int index) {
>    RangeCheck(index);
>    return elementData[index];
> }
>
> and RangeCheck looks like
>
> private void RangeCheck(int index) {
>     if (index >= size || index < 0)
>         throw new IndexOutOfBoundsException(
>         "Index: "+index+", Size: "+size);
> }
>
> So, we have an EXPLICIT range check and exception throw EVEN
> if we access
> the list through an iterator (since it also calls get()).
>
> If only they had implemented it as
>
> public Object get(int index) {
>    try {
>        return elementData[index];
>    }
>    catch(ArrayIndexOutOfBoundsException e) {
>         throw new IndexOutOfBoundsException(
>         "Index: "+index+", Size: "+size);
>    }
> }
>
> it would be much saner...
>

I think you are missing the fact that "size" is not necessarily equal to
"elementData.length" hence you need to do the check.

Jose Alberto

> Just ranting...
>    Attila.
>
>


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

Reply via email to