On Mon, 18 Mar 2002, James Strachan wrote:

> Date: Mon, 18 Mar 2002 23:45:21 -0000
> From: James Strachan <[EMAIL PROTECTED]>
> Reply-To: Jakarta Commons Developers List <[EMAIL PROTECTED]>
> To: Jakarta Commons Developers List <[EMAIL PROTECTED]>
> Subject: Re: [COLLECTIONS] [VOTE] Release Collections 2.0
>
> ----- Original Message -----
> From: "Morgan Delagrange" <[EMAIL PROTECTED]>
> > > yeah, I think I did mean ArrayIterator.  The simple way of doing this
> > > would be to use Array.getLength(array).  That does the checking for you.
> > > It also lets you calculate the length once (in the constructor) so that
> > > multiple calls to hasNext does not require the overhead of
> > > Array.getLength(...).
> >
> > OK, sounds reasonable.  FWIW, it may make sense to optimize this class
> > someday, so we don't perform unnecessary reflection on Object[] arrays.
>
> Though I didn't think you could cast all arrays to Object[] so I'd prefer to
> keep the reflection based implementation - I've certainly written code
> before that needs it. e.g.
>
> int[] foo = {1,2,3};
> Object[] bar = (Object[]) foo;
>
> The above is invalid.
>

True, but you can say

  Object bar = foo;

and then use reflection underneath to figure out that bar is really an
array (bar.getClass().isArray()) and what its component type is
(bar.getClass().getComponentType()).  Also, you can use
java.lang.reflect.Array to extract the elements for you -- for arrays of
primitives you get the corresponding wrapper objects, but the concept of
iterating over it still works.

> James
>

Craig


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to