----- Original Message ----- From: "Craig R. McClanahan" <[EMAIL PROTECTED]> > > 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.
I know - I wrote the first ArrayIterator that way ;-) I just thought Morgan was thinking of removing the reflection code and just using Object[] instead and just wanted to explain why the reflection was needed - though I think I got the wrong end of the stick and Morgan was really just talking about tuning the Object[] use case while still supporting reflection for non-Object[] types. Sorry for the confusion everyone... James -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>