java如何改变已定范型?急求!!! 这是书上的一题,做不来。请高手解答!申明一个类,此类使用私有的 ArrayList 来储存对象。使用一个Class类的引用得到第一个对象的类型之后,只允许用户插入这种类型的对象!题目就是这样。一个标点未动!求解! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 if( instanceof Class){list.add();}这样么 if( instanceof Class){list.add();}是什么意思,能说详细点吗? import java.util.ArrayList;public class Test { private ArrayList<Object> arrayList; public Test() { arrayList = new ArrayList<Object>(); } public boolean add(Object e) { if (arrayList.size() > 0) { if (arrayList.get(0).getClass().equals(e.getClass())) return arrayList.add(e); } else return arrayList.add(e); return false; } public Object get(int index) { return arrayList.get(index); } public int size() { return arrayList.size(); } public static void main(String[] args) { Test t = new Test(); t.add(new Integer(1)); t.add(new Integer(2)); t.add(new Integer(3)); t.add(new Long(4)); t.add(new Integer(5)); t.add(new Boolean(false)); t.add(new Object()); t.add(new Integer(6)); int loops = t.size(); for (int i = 0; i < loops; i++) System.out.println(t.get(i)); }} 这样你看行不行private ArrayList arrayList;Java codeif("引用的对象" instanceof Class){ arrayList = new ArrayList<Class>();list.add();} Java Application如何制作QQ好友列表那种窗体?? socket传输文件出现很诡异的错误.. java正则表达式的替换问题 HASHMAP 问题 <html:file标签,form提交不成功,内容被清空的问题。 关于jar 哪位高手可以给我解答这个问题 我给分 心情不好 连续散分~~5 :( default package 拿到一个项目的java源程序,有185个文件,怎么看?来着有分,不够再加。 泛型<T extends Car>和泛型<? extends Car> 求InstallShield2008教程
list.add();
}
这样么
list.add();
}
是什么意思,能说详细点吗?
import java.util.ArrayList;public class Test {
private ArrayList<Object> arrayList;
public Test() {
arrayList = new ArrayList<Object>();
}
public boolean add(Object e) {
if (arrayList.size() > 0) {
if (arrayList.get(0).getClass().equals(e.getClass()))
return arrayList.add(e);
} else
return arrayList.add(e);
return false;
}
public Object get(int index) {
return arrayList.get(index);
}
public int size() {
return arrayList.size();
}
public static void main(String[] args) {
Test t = new Test();
t.add(new Integer(1));
t.add(new Integer(2));
t.add(new Integer(3));
t.add(new Long(4));
t.add(new Integer(5));
t.add(new Boolean(false));
t.add(new Object());
t.add(new Integer(6));
int loops = t.size();
for (int i = 0; i < loops; i++)
System.out.println(t.get(i));
}
}
private ArrayList arrayList;Java codeif("引用的对象" instanceof Class){
arrayList = new ArrayList<Class>();
list.add();
}