我正在尝试完成一个 JCF 数组列表,它在 30 分钟前编译得很好,但现在我收到错误“ArrayList 类型不是通用的;它不能用参数进行参数化”。我已经尝试了一些事情来弄清楚,但我很茫然。这是代码:
import java.util.*;
/**
* Class to test the java.util.ArrayList class.
*/
public class Main
{
public static void main(String[] args)
{
Main myAppl = new Main();
}
public Main()
{
ArrayList<Integer> numbers = new ArrayList<Integer>();
//list creation
for (int i = 0; i < 10; i++)
numbers.add((int) (Math.random() * 100));
System.out.println("List of numbers:");
System.out.println(numbers);
Scanner in = new Scanner(System.in);
System.out.print("Please, enter an int value: ");
int x = in.nextInt();
if (numbers.contains(x))
System.out.println("Found!");
else
System.out.println("Not found!");
}
}
最佳答案
2 种可能性:
您正在使用来自第 3 方包的一些神秘的 ArrayList 而不是 java.util.ArrayList;或者
您的编译器设置是 1.5 之前的版本,或者您的有效 JDK 是 1.5 之前的版本,因此泛型不可用。
关于java - ArrayList 类型不是通用的;它不能用参数 <Integer> 参数化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22059271/