fad*_*bee -1 java methods class instanceof
使这项工作的正确语法是什么?
public boolean isTypeOf(Class type) {
return this instanceof type;
}
Run Code Online (Sandbox Code Playgroud)
我打算用它来称呼它:
foo.isTypeOf(MyClass.class);
Run Code Online (Sandbox Code Playgroud)
该方法将被覆盖,否则我将使用instanceofinplace.
public boolean isTypeOf(Class type) {
return type.isInstance(this);
}
Run Code Online (Sandbox Code Playgroud)
此方法确定给定参数是否是类的实例.如果对象是类的子类,则此方法也将起作用.
引用Javadoc:
此方法是Java语言
instanceof运算符的动态等效项.