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


基础教程推荐
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 从 python 访问 JVM 2022-01-01