What is wrong here? I get a java.lang.ClassCastException error but I can#39;t see where I have gone wrong(这里有什么问题?我收到 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
这篇关于这里有什么问题?我收到 java.lang.ClassCastException 错误,但看不到哪里出错了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:这里有什么问题?我收到 java.lang.ClassCastException 错误,但看不到哪里出错了
基础教程推荐
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
