Example usage for java.lang Class isInterface

List of usage examples for java.lang Class isInterface

Introduction

In this page you can find the example usage for java.lang Class isInterface.

Prototype

@HotSpotIntrinsicCandidate
public native boolean isInterface();

Source Link

Document

Determines if the specified Class object represents an interface type.

Usage

From source file:Main.java

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);
}

From source file:MainClass.java

public static void main(String[] unused) {
    try {/*from ww w  . j  ava 2 s.  co m*/
        String n = "java.util.List";
        Class c = Class.forName(n);

        if (c.isInterface()) {
            System.out.println(n + " is an interface");
        } else {
            System.out.println(n + " is not an interface");
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Class cls = java.lang.String.class;
    boolean isClass = !cls.isInterface(); // true

    cls = java.lang.Cloneable.class;
    isClass = !cls.isInterface(); // false

}

From source file:Main.java

public static void main(String[] args) {

    Main c = new Main();
    Class cls = c.getClass();

    // determines if the specified Class object represents an interface type
    boolean retval = cls.isInterface();
    System.out.println("It is an interface ? " + retval);
}

From source file:com.fengduo.bee.commons.core.utilities.ClassPathScanner.java

public static void main(String[] args) {
    List<Class<?>> list = new ClassPathScanner("org.springframework.core.io", new ClassFilter() {

        // ?//from  w ww . j  a  v  a  2s .  com
        public boolean accept(Class<?> clazz) {
            return clazz.isInterface();
        }
    }).scan();
    for (Class<?> clazz : list) {
        System.out.println(clazz);
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Class cc = null;
    cc = Main.class;
    System.out.println("The name of the superclass is " + cc.getSuperclass());
    System.out.println("Is SalariedEmployee an interface? " + cc.isInterface());
}

From source file:ShowClass.java

public static void main(String[] args) throws ClassNotFoundException {
    Class aClass = Class.forName("javax.swing.JComponent");
    if (aClass.isInterface()) {
        System.out.print(Modifier.toString(aClass.getModifiers()) + " " + typeName(aClass));
    } else if (aClass.getSuperclass() != null) {
        System.out.print(Modifier.toString(aClass.getModifiers()) + " class " + typeName(aClass) + " extends "
                + typeName(aClass.getSuperclass()));
    } else {//from   w w w  . j a v a  2 s. com
        System.out.print(Modifier.toString(aClass.getModifiers()) + " class " + typeName(aClass));
    }

    Class[] interfaces = aClass.getInterfaces();
    if ((interfaces != null) && (interfaces.length > 0)) {
        if (aClass.isInterface())
            System.out.print(" extends ");
        else
            System.out.print(" implements ");
        for (int i = 0; i < interfaces.length; i++) {
            if (i > 0)
                System.out.print(", ");
            System.out.print(typeName(interfaces[i]));
        }
    }

    System.out.println(" {");

    Constructor[] constructors = aClass.getDeclaredConstructors();
    for (int i = 0; i < constructors.length; i++)
        printMethodOrConstructor(constructors[i]);

    Field[] fields = aClass.getDeclaredFields();
    for (int i = 0; i < fields.length; i++)
        printField(fields[i]);

    Method[] methods = aClass.getDeclaredMethods();
    for (int i = 0; i < methods.length; i++)
        printMethodOrConstructor(methods[i]);

    System.out.println("}");
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File f = new File("c:/mysql-connector-java-5.1.18-bin.jar");
    URLClassLoader urlCl = new URLClassLoader(new URL[] { f.toURL() }, System.class.getClassLoader());

    Class mySqlDriver = urlCl.loadClass("com.mysql.jdbc.Driver");
    System.out.println(mySqlDriver.newInstance());
    System.out.println("Is this interface? = " + mySqlDriver.isInterface());

    Class interfaces[] = mySqlDriver.getInterfaces();
    int i = 1;/*www.j a va  2s  .co m*/
    for (Class _interface : interfaces) {
        System.out.println("Implemented Interface Name " + (i++) + " = " + _interface.getName());
    }

    Constructor constructors[] = mySqlDriver.getConstructors();
    for (Constructor constructor : constructors) {
        System.out.println("Constructor Name = " + constructor.getName());
        System.out.println("Is Constructor Accessible? = " + constructor.isAccessible());
    }
}

From source file:Main.java

static <T> void validateServiceClass(Class<T> paramClass) {
    if (!paramClass.isInterface())
        throw new IllegalArgumentException("Only interface endpoint definitions are supported.");
    if (paramClass.getInterfaces().length > 0)
        throw new IllegalArgumentException("Interface definitions must not extend other interfaces.");
}

From source file:Main.java

public static <T> void validateScriptInterface(Class<T> service) {
    if (!service.isInterface()) {
        throw new IllegalArgumentException("API declarations must be interfaces.");
    }/*from w w w  .j a v  a 2 s  .co  m*/
    if (service.getInterfaces().length > 0) {
        throw new IllegalArgumentException("Script interfaces must not extend other interfaces.");
    }
}