In fact, you have already found the correct answer, with a few comments needed. The other answer is simply incorrect.
-, getType() Class<?>, Class Type; Type isAssignableFrom() :
Type isAssignableFrom()Class#isAssignableFrom() Class<?>, Type
, , , Class/Type , . , Class<?> Type, , equals() Class ( Type), Object#equals(),
public boolean equals(Object obj) {
return (this == obj);
}
Object.java, Class.java .
-, , , :
if ( myField.getType() == MyOwnClass.class ) {
// Now I know myField is of type MyOwnClass
} // note that this requires a single ClassLoader to be used! Two ClassLoaders could in theory load one class with two separate Class instances
,
if ( myField.getType().getCanonicalName().equals( MyOwnClass.class.getCanonicalName() ) {
// Now I know myField is of type MyOwnClass
} // note that this uses a name comparison, not a class comparison
if ( myField.getType().isAssignableFrom( MyOwnClass.class )) {
}
tl;dr equals() Class , ==, Type - , , : .