问题描述
我有一个有界的泛型类,我们称之为泛型,其参数T扩展了抽象类Abstract:
通用类:
public class Generic<T extends Abstract> {
public <T extends Abstract> List<T> method() {
Map<String,String> map = T.getMap(); //this is the line with the error. I'll explain it below
//return statement and such
}
}
抽象类
public abstract class Abstract {
protected Map<String,String> map;
public abstract Map<String,String> getMap();
}
T在通用类中引用的类
public class class1 extends Abstract {
public class1() {
//map is inmutably defined here and assigned to the super
}
@Override
public Map<String,String> getMap() {
return super.map;
}
}
当尝试引用方法T的范围内的类中的getMap()方法时(根据抽象类定义,T的所有可能实例将具有以下错误:
非静态方法getMap()不能从静态上下文中引用
但是,任何地方都没有静态关键字。我想念什么?
谢谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)