is there a short way to load generics in listmodel?
my JList is holding a model that represents a
ArrayList<? extends MyObject> myModel;
in order to fill or get data I iterate it.
Is there a nicer way to get that desired list?I tried
list = new ArrayList<myObj>();
Collections.addAll(list, myModel.toArray())
bu开发者_开发百科t cause the array is object then it doesnt work.
is there a shorter way to load generics in listmodel ?
That should do the trick:
List<MyObject> list = java.util.Arrays.asList((MyObject[]) mymodel.toArray());
generics in a ListModel will be supported in jdk7. If you dont want to wait, you might consider to grab its sources from openJDK
精彩评论