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 错误,但看不到哪里出错了


- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01