469,319 Members | 2,445 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,319 developers. It's quick & easy.

Can't sort in Java 1.5 with generics

I've been getting odd compile errors when trying to sort while using
generics.

I have the following code:

static final List<Class> levelList;
static {
Vector<Class> v = new Vector<Class>();

v.add(myClass1.class);
v.add(myClass2.class);
v.add(myClass3.class);

Collections.sort(v);
levelList = Collections.unmodifiableList(v);
}

which causes the compile error:

C:\dev\cvs.kitfox.com\scarlet\src\com\kitfox\scarl et\levels\ScarletLevelList.java:34:
cannot find symbol
symbol : method sort(java.util.List<java.lang.Class>)
location: class java.util.Collections
Collections.sort((List<Class>)v);
However, if I change the sort command to

Collections.sort((List)v);

Things work. Is there a way to write the above code so that it
compiles correctly with generics?

Mark McKay
--
http://www.kitfox.com

Jul 17 '05 #1
0 5407

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

22 posts views Thread by Matthew Louden | last post: by
9 posts views Thread by babylon | last post: by
17 posts views Thread by atgraham | last post: by
458 posts views Thread by wellstone9912 | last post: by
16 posts views Thread by coosa | last post: by
148 posts views Thread by BillJosephson | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.