<分区>
给定一个 Class<?> superType
和一个 Object subInstance
, 之间有什么区别
superType.isInstance(subInstance)
和
superType.isAssignableFrom(subInstance.getClass())
(如果有的话)?
<分区>
给定一个 Class<?> superType
和一个 Object subInstance
, 之间有什么区别
superType.isInstance(subInstance)
和
superType.isAssignableFrom(subInstance.getClass())
(如果有的话)?
最佳答案
在场景中,没有区别。
两种方法的区别在于参数。一种使用对象,另一种使用类:
Determines if the specified Object is assignment-compatible with the object represented by this Class.
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 - Class#isInstance 与 Class#isAssignableFrom,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19664009/