Object ele=a.get(i);
if(ele instanceof java.lang.Integer){//cast to integer:
print("found Int");
}else{ //cast to string:
print("found: "+ele.getClass());
}
//prints: found: class com.cycling74.max.Atom$IntAtom
这是更大块代码的一部分,但这是相关部分。我需要知道如何通过cycling74检查Atom类中元素的类型。如何检查自定义集合中元素的java数据类型?
if(ele instanceof com.cycling74.max.Atom$IntAtom)
//ERROR: com.cycling74.max.Atom.IntAtom has private access in com.cycling74.max.Atom
任何想法?? 非常感谢 - 这真的是我的头!
如果该类声明为private,则不能在com.cycling74.max.Atom类之外执行'instanceof'。 – 2011-03-30 16:14:20