Check whether a class is an interface in Java

Description

The following code shows how to check whether a class is an interface.

Example


// ww w. j a va 2s .co  m
public class Main {
  public static void main(String[] argv) throws Exception {

    Class clazz = String.class;
    boolean isInterface = clazz.isInterface();
    System.out.println("Is Interface = " + isInterface);
    
    clazz = Cloneable.class;
    isInterface = clazz.isInterface();
    System.out.println("Is Interface = " + isInterface);
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Reflection »




Annotation
Array
Class
Constructor
Field
Generics
Interface
Method
Modifier
Package
Proxy