[biojava-dev] a bit offtopic: javac 1.5 & generics

Michael Heuer heuermh at acm.org
Thu Feb 5 17:51:26 EST 2004


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



More information about the biojava-dev mailing list