[英]Object instanceof Object
I want to check if an object is instance of an objects class. 我想检查一个对象是否是对象类的实例。
public Stack<Object> getObject(int x, int y, int x2, int y2, Object type, Stats stats){
Stack<Object> ob = new Stack<Object>();
for(Object o : stats.map){
if(o instanceof type.getClass()){//Not working
if((!((o.x < x && o.x < x2) || (o.x * o.size > x && o.x * o.size > x2)) &&
!((o.y < y && o.y < y2) || (o.y * o.size > y && o.y * o.size > y2)))){
ob.push(o);
}
}
}
return ob;
}
I have made some classes that exctends other classes: 我开设了一些超越其他课程的课程:
(Tree, Iron, Stone) extends Resouce extends Object (树,铁,石头)扩展资源扩展对象
Person extends Object 人延伸对象
You cannot use instanceof
with Class
objects. 您不能将instanceof
与Class
对象一起使用。
You can check it using: 您可以使用以下方法进行检查:
type.getClass().isInstance(o)
您可以使用
if(o.getClass() instanceof type.getClass()){
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.