将instanceof与类Object一起使用 [英] Using instanceof with a class Object
本文介绍了将instanceof与类Object一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使此工作正确的语法是什么?
What's the correct syntax to make this work?
public boolean isTypeOf(Class type) {
return this instanceof type;
}
我打算用:
foo.isTypeOf(MyClass.class);
该方法将被覆盖,否则我将直接使用 instanceof
.
The method will be overriden, otherwise I would just use instanceof
inplace.
推荐答案
使用此方法确定给定的参数是否是该类的实例.如果对象是该类的子类,则此方法也将起作用.
This method determines if the given parameter is an instance of the class. This method will also work if the object is a sub-class of the class.
引用Javadoc:
此方法是Java语言
instanceof
运算符的动态等效项.
这篇关于将instanceof与类Object一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文