当前位置: 代码迷 >> Java相关 >> uses unchecked or unsafe operations??
  详细解决方案

uses unchecked or unsafe operations??

热度:827   发布时间:2006-07-09 23:30:55.0
uses unchecked or unsafe operations??

package c08.cotroller;
import java.util.*;

public class Controller
{
private List eventList = new ArrayList();
public void addEvent(Event c)
{
eventList.add(c);
}
public void run()
{
while(eventList.size() > 0)
{
for(int i = 0; i < eventList.size(); i++)
{
Event e = (Event)eventList.get(i);
if(e.ready())
{
System.out.println(e);
e.action();
eventList.remove(i);
}
}
}
}
}


Note: E:\College\java\Projects\Controller.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
编译出现这个,然后在以后的import c08.controller.*; 的时候就显示cannot access Controller.

这是什么原因呢??求助。。。

搜索更多相关的解决方案: uses  operations  unchecked  unsafe  

----------------解决方案--------------------------------------------------------

这是1.5的泛型,你ArrayList没有指定它能装什么对象,所以就不安全
仔细看看泛型方面的文章吧
改为
List<Event> eventList = new ArrayList<Event>();
就可以去掉警告 了


----------------解决方案--------------------------------------------------------
!!!!!!!
真的去掉了!
好厉害!!!
我刚开始学java,所以还有很多不懂的地方,正在看thinking in java,把里面一个一个的程序自己慢慢来实现,感觉java真是太有趣了!
多谢指导哦!!!!
:)
----------------解决方案--------------------------------------------------------
  相关解决方案