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

package org.kodejava.example.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("Cloneable is an interface = " + isInterface);

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


Programmer, runner, recreational diver, live in the island of Bali, Indonesia. Mostly programming in Java, Spring Framework, Hibernate / JPA. Support me by donating.

Leave a Reply