List of usage examples for java.lang Class getInterfaces
public Class<?>[] getInterfaces()
From source file:Main.java
public static void main(String[] argv) throws Exception { Class cls = int.class; Class[] intfs = cls.getInterfaces(); // [] }
From source file:Main.java
public static void main(String[] argv) throws Exception { Class cls = java.util.List.class; Class[] intfs = cls.getInterfaces(); // java.util.Collection }
From source file:Main.java
public static void main(String[] args) { Class cls = Thread.class; System.out.println("Class = " + cls.getName()); Class[] c = cls.getClasses(); System.out.println("Classes = " + Arrays.asList(c)); // returns an array of interfaces Class[] i = cls.getInterfaces(); System.out.println("Interfaces = " + Arrays.asList(i)); }
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;//from ww w . j av a 2s . c o 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:HasBatteries.java
public static void main(String[] args) { Class c = null; try {/*from ww w .ja v a 2s .co m*/ c = Class.forName("FancyToy"); } catch (ClassNotFoundException e) { System.out.println("Can't find FancyToy"); System.exit(1); } printInfo(c); Class[] faces = c.getInterfaces(); for (int i = 0; i < faces.length; i++) printInfo(faces[i]); Class cy = c.getSuperclass(); Object o = null; try { // Requires default constructor: o = cy.newInstance(); // (*1*) } catch (InstantiationException e) { System.out.println("Cannot instantiate"); System.exit(1); } catch (IllegalAccessException e) { System.out.println("Cannot access"); System.exit(1); } printInfo(o.getClass()); }
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 . java2 s . c o m 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:SampleInterface.java
static void printInterfaceNames(Object o) { Class c = o.getClass(); Class[] theInterfaces = c.getInterfaces(); for (int i = 0; i < theInterfaces.length; i++) { String interfaceName = theInterfaces[i].getName(); System.out.println(interfaceName); }/* w w w. j a v a 2s . c o m*/ }
From source file:Main.java
public static boolean isImplementInterface(Class<?> interfaceClass, Class<?> implementClass) { for (Class<?> subClass : implementClass.getInterfaces()) { if (subClass.equals(interfaceClass)) { return true; }// w w w. ja v a2 s . c o m } return false; }
From source file:MyClass.java
public static String getClassInterfaces(Class c) { Class[] interfaces = c.getInterfaces(); String interfacesList = null; if (interfaces.length > 0) { String[] interfaceNames = new String[interfaces.length]; for (int i = 0; i < interfaces.length; i++) { interfaceNames[i] = interfaces[i].getSimpleName(); }/* w w w.j a va 2 s . c o m*/ interfacesList = String.join(", ", interfaceNames); } return interfacesList; }
From source file:Main.java
private static void exploreSuperInterfaces(Class<?> intf, Set<Class<?>> traitInterfaces) { for (Class<?> sup : intf.getInterfaces()) { traitInterfaces.add(sup);/*www. j av a 2 s . c o m*/ exploreSuperInterfaces(sup, traitInterfaces); } }