[biojava-dev] a bit offtopic: javac 1.5 & generics
Michael Heuer
heuermh at acm.org
Fri Feb 6 16:48:59 EST 2004
Thanks to everyone for the help. To summarize what I've found,
given
Set<Foo> foos = new HashSet<Foo>();
this works because foos is already templated
Set<Foo> unmodifiableFoos = Collections.unmodifiableSet(foos);
the cast here is fine but unnecessary
Set<Foo> unmodifiableFoos = (Set<Foo>) Collections.unmodifiableSet(foos);
this syntax also works but is unnecessary
Set<Foo> unmodifiableFoos = Collections.<Foo>unmodifiableSet(foos);
gives an unchecked assignment warning
Set<Foo> emptyFoos = Collections.EMPTY_SET;
gives an unchecked cast warning
Set<Foo> emptyFoos = (Set<Foo>) Collections.EMPTY_SET;
illegal expression
Set<Foo> emptyFoos = Collections.<Foo>EMPTY_SET;
ok
Set<Foo> emptyFoos = Collections.emptySet();
compile error, found Set<Object> required Set<Foo>
Set<Foo> emptyFoos = (Set<Foo>) Collections.emptySet();
ok
Set<Foo> emptyFoos = Collections.<Foo>emptySet();
michael
On Fri, 6 Feb 2004, Thomas Down wrote:
> Once upon a time, Michael Heuer wrote:
> >
> > Guess I should have read this paper before I began
> >
> > Adding Wildcards to the Java Programming Language
> > > http://www.bracha.org/wildcards.pdf
> >
> >
> > but in short, this works
> >
> > Set<Foo> foos = new HashSet<Foo>();
> >
> > Set<Foo> unmodifiableFoos = (Set<Foo>) Collections.unmodifiableSet(foos);
> >
> > and this does not
> >
> > Set<Foo> emptyFoos = (Set<Foo>) Collections.EMPTY_SET;
>
> No, that doesn't work :-(.
>
> You can, however, do:
>
> Set<Foo> emptyFoos = Collections.emptySet();
>
> Better than nothing, anyway.
>
> Thomas.
> _______________________________________________
> biojava-dev mailing list
> biojava-dev at biojava.org
> http://biojava.org/mailman/listinfo/biojava-dev
>
More information about the biojava-dev
mailing list