Java,队列的迭代器错误。

Java,队列的迭代器错误。,java,Java,我的代码如下。我只是在Eclipse中有一个警告说“迭代器是一个原始类型。对泛型类型迭代器的引用应该参数化”。这意味着什么,我如何正确地修复它 import java.util.Iterator; import java.util.LinkedList; import java.util.Queue; public class EmployeeList { Queue<Employee> empList = new LinkedList<Employee>(

我的代码如下。我只是在Eclipse中有一个警告说“迭代器是一个原始类型。对泛型类型迭代器的引用应该参数化”。这意味着什么,我如何正确地修复它

import java.util.Iterator;
import java.util.LinkedList;
import java.util.Queue;


public class EmployeeList 
{
    Queue<Employee> empList = new LinkedList<Employee>();

    Employee find (String nm)
    {
    Iterator it = empList.iterator(); //Iterator is a raw type. References to generic type Iterator<E> should be parameterized
    while(it.hasNext())
    {
        Employee em = (Employee)it.next();
        if(em.name.equals(nm))
        {
            return em;
        }   
    }
    return null;
}
import java.util.Iterator;
导入java.util.LinkedList;
导入java.util.Queue;
公共类雇员名单
{
Queue empList=new LinkedList();
员工查找(字符串nm)
{
迭代器it=empList.Iterator();//迭代器是原始类型。对泛型类型迭代器的引用应参数化
while(it.hasNext())
{
Employee em=(Employee)it.next();
如果(em.name.等于(nm))
{
返回em;
}   
}
返回null;
}

添加到迭代器将清除警告,当您向迭代器添加泛型类型时,您不需要显式强制转换next()调用,因为可以保证现在迭代器指向Employee的类型

 Iterator<Employee> it = empList.iterator();
    while(it.hasNext())
    {
        Employee em = it.next();
        if(em.name.equals(nm))
        {
            return em;
        }   
    }
Iterator it=empList.Iterator();
while(it.hasNext())
{
Employee em=it.next();
如果(em.name.等于(nm))
{
返回em;
}   
}

添加到迭代器将清除警告,当您向迭代器添加泛型类型时,您不需要显式强制转换next()调用,因为可以保证现在迭代器指向Employee的类型

 Iterator<Employee> it = empList.iterator();
    while(it.hasNext())
    {
        Employee em = it.next();
        if(em.name.equals(nm))
        {
            return em;
        }   
    }
Iterator it=empList.Iterator();
while(it.hasNext())
{
Employee em=it.next();
如果(em.name.等于(nm))
{
返回em;
}   
}

这就是它要求“参数化迭代器”的意思?这就是它要求“参数化迭代器”的意思?