Class cls1 = String.class; Class cls2 = Object.class; boolean result = cls1.isAssignableFrom(cls2); System.out.println(result);
ListIn this example, we create a list of strings and get the class object of the list. We then compare the List class with the class of the list object. The result is true because the ArrayList class implements the List interface. The Class isAssignableFrom method is part of the Java Reflection API and can be found in the java.lang package.stringList = new ArrayList<>(); Class cls1 = stringList.getClass(); Class cls2 = List.class; boolean result = cls2.isAssignableFrom(cls1); System.out.println(result);