我有
public class Entity
在哪个工作班上:
public class Table<Target extends Entity>
{
public boolean save (Target target)
public Target load (int id)
}
直到我将 Table 类的这个对象放在数据库类 Map 中,一切都很好,但是:
public class Database
{
public String name;
public Map<String, Table<? extends Entity>> tables = new HashMap <String, Table<? extends Entity>> ();
public Context context;
public int version;
public Database (Context context, int version)
{
this.context = context;
this.version = version;
}
public void add (Table<? extends Entity> table)
{
tables.put(table.name, table);
}
public Table <? extends Entity> table (String name)
{
return (Table<? extends Entity>) tables.get(name);
}
}
假设我们有:
public class Apple extends Entity
我希望这段代码能够工作:
//init
database = new Database(getBaseContext(), 4);
new Table<Apple> (database, Apple.class);
//this is where solution need occurs !
database.table("apples").save (new Apple("green apple"));
类型 Table(capture#1-of ? extends Entity) 中的方法 save(capture#1-of ? extends Entity) 不适用于参数(注)
如何使 map.get 方法起作用?