[biojava-dev] a bit offtopic: javac 1.5 & generics
Michael Heuer
heuermh at acm.org
Thu Feb 5 18:44:36 EST 2004
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;
I do like the new enhanced for loops, instead of
for (Iterator i = foos.iterator(); i.hasNext(); )
{
Foo f = (Foo) i.next();
...
you just write
for (Foo f : foos)
{
...
For fun I'm going to try a keyword-enum-based instead of Bloch-style
Enum class-based version of the static alphabet codebase I posted
earlier.
michael
On Thu, 5 Feb 2004, Michael Heuer wrote:
> Hello,
>
> With the new beta release of the java 1.5 SDK and tools [1-3] I've been
> working on adding generics support to one of my projects:
>
> > http://sf.net/projects/vocabulary
>
> $ cvs co -r ADDING_JAVA1_5_GENERICS_BRANCH dsh-vocabulary
>
>
> I'm a little bit confused by a couple of things. How would you use the
> wrapper classes in Collections with type safety?
>
> ex.
>
> Set<Foo> foos = new HashSet<Foo>();
>
> Set<Foo> emptyFoos = Collections.EMPTY_SET;
>
> Set<Foo> unmodifiableFoos = Collections.unmodifiableSet(foos);
>
>
> This compiles but gives me warnings about unchecked assignments. Can I
> just cast the EMPTY_SET? What about the wrapper class returned by
> unmodifiableSet?
>
> michael
>
>
> [1] j2sdk v1.5.0-beta, http://java.sun.com/j2se/1.5.0/download.jsp
> [2] ant v1.6.1beta1, http://ant.apache.org
> [3] maven v1.0-rc1-SNAPSHOT, http://maven.apache.org
>
> _______________________________________________
> biojava-dev mailing list
> biojava-dev at biojava.org
> http://biojava.org/mailman/listinfo/biojava-dev
>
More information about the biojava-dev
mailing list