我似乎无法找到我在静态方法中使用非静态引用的位置,代码是:
public class Item {
public static final Map ITEM_STATUSES = new HashMap();
static {
ITEM_STATUSES.put(STATUS_NEW, "New");
}
public static String getItemStatusFromName(final String p_itemStatusName) {
Iterator statusIterator = Item.ITEM_STATUSES.entrySet().iterator();
while (statusIterator.hasNext()) {
Entry statusEntry = (Entry)statusIterator.next();
if (((String)statusEntry.getValue()).equals(p_itemStatusName)) {
return (String)statusEntry.getKey();
}
}
return "";
}
}
而在另一个班级
private void getName(){
String itemStatus = Item.getItemStatusFromName(p_itemStatusName);
}
编译器说:无法从类型Item中对非静态方法getItemStatusFromName(String)进行静态引用