java.util.Enumeration en = javax.comm.CommPortIdentifier.getPortIdentifiers();
int i=0;
while(en.hasMoreElements())
{
    portId = (javax.comm.CommPortIdentifier)en.nextElement();
    if(portId.getPortType() == javax.comm.CommPortIdentifier.PORT_SERIAL)
    {   
list.addItem(portId.getName());
i++;
    }
}
其中en.nextElement()报错信息如下:
Type safety: The method nextElement() belongs to the raw type Enumeration. References to generic type Enumeration<E> should be parameterized
请问这段代码要如何修改?谢谢.

解决方案 »

  1.   

    我想你在使用的应该是J2SE5.0吧。在J2SE5.0中Enumeration已经被泛型化了。你看一下getPortIdentifiers返回的类型是不是Enumeration<javax.comm.CommPortIdentifier>程序可以变成这样:
    java.util.Enumeration<javax.comm.CommPortIdentifier> en = 
                                          javax.comm.CommPortIdentifier.getPortIdentifiers();
    int i=0;
    while(en.hasMoreElements())
    {
        portId = en.nextElement();
        if(portId.getPortType() == javax.comm.CommPortIdentifier.PORT_SERIAL)
        {   
            list.addItem(portId.getName());
            i++;
        }
    }