这里有什么问题?我收到 java.lang.ClassCastException 错误,但看不到哪里出错了
这是我第一次真正使用列表和队列,所以这可能是一个非常简单的错误.是因为我的队列中充满了无法转换为整数的对象吗?
This is the first time I have really used Lists and Queues so this might be a very simple mistake. Is it because my queue is full of objects that can't be cast to integers?
//populate array
for(int i=0; i<11; i++){
numberarray[i] = i;
}
// populate list with numbers from array
List numList = Arrays.asList(numberarray);
Collections.shuffle(numList);
Queue queue = new LinkedList();
queue.addAll(numList);
int num1 = (Integer) queue.poll();
assignPictures(button01, num1);
推荐答案
你真的应该使用泛型和 ArrayList/ArrayDeque,除非它对性能非常关键,并且你使用了很多原子类型,比如 int.那你应该看看http://labs.carrotsearch.com/hppc.html
You really should use Generics and ArrayList/ArrayDeque unless it's really performance critical and you use a lot of atomic types like int. Then you should have a look at http://labs.carrotsearch.com/hppc.html
相关文章