【发布时间】:2014-02-27 04:48:27
【问题描述】:
我正在尝试完成一个 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!");
}
}
【问题讨论】:
-
你用什么版本的Java编译?
-
我怀疑你的类路径中还有其他
ArrayList类。将import java.util.*;替换为java.util.ArrayList,我相信它肯定会起作用。 -
System.out.println(numbers.getClass());输出什么?
标签: java generics arraylist integer