开发者

is there a short way to load generics in listmodel?

开发者 https://www.devze.com 2023-02-24 10:08 出处:网络
my JList is holding a model that represents a ArrayList<? extends MyObject> myModel; in order to fill or get data I iterate it.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消