【发布时间】:2012-03-13 18:29:54
【问题描述】:
我正在学习 Java 泛型,因为我想实现这个:
我有 2 个使用 1 个公共类的类,在这个公共类中,我想创建一个泛型类的对象。这里有一段我的代码,所以这将是最简单的。
//MyFirstClass.java
class MyFirstClass{
...
MyExpandableListAdapter<FirstFilter> mAdapter = new MyExpandableListAdapter<FirstFilter>();
...
}
//MySecondClass.java
class MySecondClass{
...
MyExpandableListAdapter<SecondFilter> mAdapter = new MyExpandableListAdapter<SecondFilter>();
...
}
//common class MyExpandableListAdapter.java
public class MyExpandableListAdapter<E extends Filter> extends BaseExpandableListAdapter implements Filterable {
private E filter;
...
public Filter getFilter(){
if (filter== null)
filter = new <E>(); // Here I want to create an Object, but I get an error on <E>
return filter;
}
}
有可能吗?我怎么能做到? 请帮我。非常感谢。
【问题讨论】: