type Iterator does not take parameters
在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(1,"mother"); map.put(2,"wife"); map.put(3,"father"); } public String next() { Random rand = new Random(); int i = rand.nextInt(2) + 1; 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 = 0; i < 10; 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