Just a thought. How about doing this...
public class CollectionUtils {
public static final Iterator EMPTY_ITERATOR
= Collections.EMPTY_LIST.iterator();
...
}
As the implementation of EmptyList in Collections already contains an
implementation of an EmptyIterator. Though for some reason
EMPTY_LIST.iterator() creates a new instance each time.
James
----- Original Message -----
From: "Christopher Elkins" <[EMAIL PROTECTED]>
To: "Jakarta Commons Developers List" <[EMAIL PROTECTED]>
Sent: Thursday, November 22, 2001 6:14 AM
Subject: Re: [PATCH][Collections] Add empty iterator to CollectionUtils
> On Wed, Nov 21, 2001 at 11:58:07PM -0500, [EMAIL PROTECTED] wrote:
> >
> > What's your view on making the EmptyIterator class a proper public
class.
> > Is there a strong reason for deciding that all EmptyIterators must be
> > the same instance?
> >
> > It's probably just a style thing, but I wanted to check.
>
> There are a few reasons:
> - It parallels the set theory notion that all empty sets are really the
> same empty set.
> - It parallels Collections.EMPTY_[LIST|MAP|SET].
> - Because it's immutable it's perfectly valid to return the same
instance.
> (It also offers a minimal performance gain.)
>
> Ultimately I guess it is a matter of style. Indeed, my local
implementation
> is a proper class; I took the opportunity of contributing it to the
Commons
> as an excuse for implementing it the right way (where "right" is justified
> using the above reasons). :-)
>
> --
> Christopher Elkins
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>