Galder, what JDK are you using? OpenJDK 1.7 uses EmptyIterator.EMPTY_ITERATOR since 2007:<br><br><a href="http://hg.openjdk.java.net/jdk7/jdk7/jdk/annotate/37a05a11f281/src/share/classes/java/util/Collections.java">http://hg.openjdk.java.net/jdk7/jdk7/jdk/annotate/37a05a11f281/src/share/classes/java/util/Collections.java</a><br>
<br>I don&#39;t have JDK 1.6 sources on hand to check, but I don&#39;t think it&#39;s worth optimizing for such an old version anyway.<br><br>Cheers<br>Dan<br><br><br><div class="gmail_quote">On Fri, Oct 19, 2012 at 5:50 PM, Vladimir Blagojevic <span dir="ltr">&lt;<a href="mailto:vblagoje@redhat.com" target="_blank">vblagoje@redhat.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Cool! Did not know about this! Is this original idea or others are<br>
already doing this?<br>
<div class="HOEnZb"><div class="h5">On 12-10-19 8:31 AM, Galder Zamarreņo wrote:<br>
&gt; Hi all,<br>
&gt;<br>
&gt; Re: <a href="https://github.com/galderz/infinispan/commit/0609207d13216de81d77ff51dc20652ce270c635" target="_blank">https://github.com/galderz/infinispan/commit/0609207d13216de81d77ff51dc20652ce270c635</a><br>
&gt;<br>
&gt; Please avoid using these JDK methods where possible. I&#39;ve created alternative versions in InfinispanCollections util class that provide a better implementation.<br>
&gt;<br>
&gt; The problem with the JDK versions is that even if these collections are immutable, if you wanna iterate them (i.e. for(X : emptySet) ), they&#39;ll create a brand new Iterator every time they&#39;re looped, and that generates useless garbage.<br>

&gt;<br>
&gt; The InfinispanCollections versions of emptyX will return a constant singleton iterator which avoids this problem, and avoids the need for client code to check if the collection is empty before looping.<br>
&gt;<br>
&gt; Cheers,<br>
&gt; --<br>
&gt; Galder Zamarreņo<br>
&gt; <a href="mailto:galder@redhat.com">galder@redhat.com</a><br>
&gt; <a href="http://twitter.com/galderz" target="_blank">twitter.com/galderz</a><br>
&gt;<br>
&gt; Project Lead, Escalante<br>
&gt; <a href="http://escalante.io" target="_blank">http://escalante.io</a><br>
&gt;<br>
&gt; Engineer, Infinispan<br>
&gt; <a href="http://infinispan.org" target="_blank">http://infinispan.org</a><br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; infinispan-dev mailing list<br>
&gt; <a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br>
<br>
_______________________________________________<br>
infinispan-dev mailing list<br>
<a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br>
</div></div></blockquote></div><br>