泛型通配符只能用于方法的参数

不能用对象定义

public class Test {

    public static void main(String[] args) {

        ArrayList<String> list = new ArrayList<>();
//ArrayList<?> list = new ArrayList<>();//不能这样定义
list.add("good");
list.add("bad"); testMain(list);
} private static void testMain(ArrayList<?> list) { Iterator<?> iterator = list.iterator();
while (iterator.hasNext())
{
Object next = iterator.next();
System.out.println(next);
} }
}
05-11 17:53