我想在java中声明匿名数组列表,以便构造函数列表的性质可以用任何类型的对象进行初始化。例如:
ArrayList<Anonymous> list;
public AdapterChatWindow(Activity act, ArrayList<CommentData> list, String extras) {
this.act = act;
this.list = list;
}
public AdapterChatWindow(Activity act, ArrayList<ChatHistory> list) {
this.act = act;
this.list = list;
}
这可能吗?有替代解决方案吗?这对于列表类型的数据结构可能吗?
最佳答案
您可以使用泛型类型:
public class AdapterChatWindow<T>
{
ArrayList<T> list;
public AdapterChatWindow(Activity act, ArrayList<T> list, String extras)
// ....
然后像这样使用它:
AdapterChatWindow<Foo> acw = new AdapterChatWindow<Foo>(...);
关于java - 如何在java中声明匿名数组列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29007462/