472,145 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

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 5486

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 Saiars | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.