继承和泛型的新手,如果我的问题很愚蠢,请多多包涵:
我有以下内容:
public abstract class car {
private long id;
private String name;
public car (long id, String name) {
this.id = id;
this.name = name;
}
public final long getID(){
return id;
}
public final String getName(){
return name;
}
}
public class sedan extends car {
public sedan(long id, String name) {
super (id, name);
}
...
}
public class jeep extends car {
public jeep(long id, String name) {
super (id, name);
}
...
}
我正在尝试为微调器扩展 ArrayAdapter,如下所示:
public class DropdownAdapter extends ArrayAdapter<car> {
private Context context;
private List<car> values;
public DropdownAdapter(Context context, int textViewResourceId, List<car> values) {
super(context, textViewResourceId, values);
this.context = context;
this.values = values;
}
...
}
当我尝试使用它时,问题就来了:
adapter = new DropdownAdapter (this, android.R.layout.simple_spinner_item, lstSedan);
会给我错误:构造函数 DropdownAdapter (ScreenItemList, int, List< 轿车 >) 未定义
adapter = new DropdownAdapter (this, android.R.layout.simple_spinner_item, lstJeep);
会给我错误:构造函数 DropdownAdapter (ScreenItemList, int, List< jeep >) is undefined
这里有什么问题?当 lstSedan 或 lstJeep 从汽车派生时,为什么我不能使用它们作为参数?我该如何解决这个问题?谢谢!