Checking a class type (.class) is equal to some other class type

Yes, that code is valid – if the two classes have been loaded by the same classloader. If you want the two classes to be treated as equal even if they’ve been loaded by different classloaders, possibly from different locations, based on the fully-qualified name, then just compare fully-qualified names instead.

Note that your code only considers an exact match, however – it won’t provide the sort of “assignment compatibility” that (say) instanceof does when seeing whether a value refers to an object which is an instance of a given class. For that, you’d want to look at Class.isAssignableFrom.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)