是否可以将instanceof与两个不同数组中的两个元素一起使用?
例如:if(arrayA[c] instanceof arrayB[c]){}
我尝试了上面的代码,但出现以下错误:
error: ']' expected: if(arrayA[c] instanceof arrayB[c]){}
^
error: ';' expected: if(arrayA[c] instanceof arrayB[c]){}
^
error: illegal start of expression: if(arrayA[c] instanceof arrayB[c]){}
^
最佳答案
您可以使用Class.isAssignableFrom() .
来自javadoc:
Determines if the class or interface represented by this Class object is either the same as, or is a superclass or superinterface of, the class or interface represented by the specified Class parameter.
关于java - 通过instanceof使用数组的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24490892/