jeudi 8 juin 2023

Which method is equivalent to the instanceof operator in Java?

I need to check if an object is instance of a class that is get at runtime by it's name. I can't use Class.isInstance, because I can't create an instance of the class

Class.isAssignableFrom always returns false, this is the code that I am using:

if (pm.getClass().isAssignableFrom(Class.forName("java.lang.reflect.Proxy"))) { ...

Using pm instanceof Proxy true is returned.





Aucun commentaire:

Enregistrer un commentaire