type Iterator does not take parameters

时间:2024-10-02 08:07:13

在ubuntu编译java程序时报错:type Iterator does not take parameters

源码如下:

package object;
import java.util.*;
class Generate{
Map<Integer,String> map = new HashMap<Integer, String>();
{
map.put(,"mother");
map.put(,"wife");
map.put(,"father");
}
public String next()
{
Random rand = new Random();
int i = rand.nextInt() + ;
return map.get(i);
}
} public class Iterator1{
public static void main(String[] args)
{
Generate g = new Generate();
Collection<String> cll = new ArrayList<String>();
for( int i = ; i < ; i++)
cll.add(g.next());
Iterator<String> iterator = cll.iterator();
while(iterator.hasNext())
System.out.println(iterator.next());
System.out.println();
}
}

报错原因:包里面有之前编写的一个Iterator类,编译时优先调用了包里的Iterator而没有调用java.util里面的Iterator