You should use isAssignableFrom
:
if (YourInterface.class.isAssignableFrom(clazz)) {
...
}
More Related Contents:
- Can you find all classes in a package using reflection?
- How do I programmatically compile and instantiate a Java class?
- Modify a class definition’s annotation string parameter at runtime
- Gson TypeToken with dynamic ArrayList item type
- Java Reflection Performance
- Can I obtain method parameter name using Java reflection?
- How to create a generic array in Java?
- How to solve InaccessibleObjectException (“Unable to make {member} accessible: module {A} does not ‘opens {package}’ to {B}”) on Java 9?
- How do I read all classes from a Java package in the classpath?
- Get all of the Classes in the Classpath
- Printing debug info on errors with java 8 lambda expressions
- Instantiating object of type parameter
- How to convert a Java object (bean) to key-value pairs (and vice versa)?
- Copy all values from fields in one class to another through reflection
- Getting Class type from String
- Getting value of public static final field/property of a class in Java via reflection
- How to get Method Parameter names in Java 8 using reflection?
- Changing private final fields via reflection
- Accessing Java static final variable value through reflection
- Dumping a java object’s properties
- Check if a Class Object is subclass of another Class Object in Java
- How to work with varargs and reflection
- Java Reflection Beans Property API
- Java: newInstance of class that has no default constructor
- Java Reflection calling constructor with primitive types
- Find out which classes of a given API are used
- Disable Java reflection for the current thread
- Java getMethod with subclass parameter
- Java introspection and reflection
- Get jar version in runtime