【发布时间】:2012-06-11 05:35:54
【问题描述】:
我有一些遗留代码想要升级到泛型:
/**
* Places in this World
*/
public Map places;
/**
* Players watching this World
*/
public Collection players;
/**
* A reference to the Adventure using this World
*/
public Adventure owner;
/**
* Create a World. `a' is a reference to the Frame itself.
* This reference is used when loading images and sounds.
*
* @param a An instance of adventure.
*/
public World( Adventure a ) {
places = new HashMap();
players = new LinkedList();
owner = a;
}
我的 IDE 警告我,我没有参数化变量 places 和 players 所以我应该在这段代码中添加泛型,但是如何?当我将<> 或<Place> 添加到“places”对象时,它说它不是泛型,所以我这样做结果是错误的。您能告诉我如何将这部分代码现代化为使用泛型吗?
谢谢
【问题讨论】:
标签: java model-view-controller oop