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("Is Interface = " + isInterface);

        //
        // Checking whether String is an interface or class
        //
        clazz = String.class;
        isInterface = clazz.isInterface();
        System.out.println("Is Interface = " + isInterface);
    }
}

Wayan Saryada

Programmer, runner, recreational diver, currently living in the island of Bali, Indonesia. Mostly programming in Java, creating web based application with Spring Framework, Hibernate / JPA.

Leave a Reply