Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何检查Class<?>对象类型?
Class<?>
我有方法:
public void method(Class<?> class1){ }
我想检查是否class1是InputStream.class.
class1
InputStream.class
class1 == InputStream.class
或者
InputStream.class.isAssignableFrom(class1)
取决于您是要检查相等性还是您有一个类对象,其实例 obj 将遵守(obj instanceof InputStream)而不必完全是InputSream.
(obj instanceof InputStream)
InputSream