How do I know if a class object is an interface or a class?

package org.kodejava.lang;

public class CheckForInterface {
    public static void main(String[] args) {
        // Checking whether Cloneable is an interface or class
        Class<?> clazz = Cloneable.class;
        boolean isInterface = clazz.isInterface();
        System.out.println(clazz.getName() + " is an interface = " + isInterface);

        // Checking whether String is an interface or class
        clazz = String.class;
        isInterface = clazz.isInterface();
        System.out.println(clazz.getName() + " is an interface = " + isInterface);
    }
}
java.lang.Cloneable is an interface = true
java.lang.String is an interface = false

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.