List of usage examples for java.lang Class isInterface
@HotSpotIntrinsicCandidate public native boolean isInterface();
From source file:SampleCheckInterface.java
static void verifyInterface(Class c) { String name = c.getName();/*from w w w . j a v a 2 s . c om*/ if (c.isInterface()) { System.out.println(name + " is an interface."); } else { System.out.println(name + " is a class."); } }
From source file:Main.java
static <T> void validateInterface(Class<T> clientInterface) { if (!clientInterface.isInterface()) { throw new IllegalArgumentException("Monkey, debe ser una interfaz"); }/* w w w .j ava2 s . c o m*/ if (clientInterface.getInterfaces().length > 0) { throw new IllegalArgumentException("Monkey, no debe implementar de otra interfaz"); } }
From source file:Main.java
static void findAllInterfaces(Class c, Set<Class> interfaces) { if (c.isInterface()) { interfaces.add(c);//from ww w . j a v a 2s . c om } Class s = c.getSuperclass(); if (s != null) { findAllInterfaces(s, interfaces); } Class[] is = c.getInterfaces(); for (int i = 0; i < is.length; i++) { findAllInterfaces(is[i], interfaces); } }
From source file:HasBatteries.java
static void printInfo(Class cc) { System.out.println("Class name: " + cc.getName() + " is interface? [" + cc.isInterface() + "]"); }
From source file:Main.java
public static void print_class(Class c) { if (c.isInterface()) { System.out.print(Modifier.toString(c.getModifiers()) + " " + typename(c)); } else if (c.getSuperclass() != null) { System.out.print(Modifier.toString(c.getModifiers()) + " class " + typename(c) + " extends " + typename(c.getSuperclass())); } else {//ww w . ja va 2 s . c o m System.out.print(Modifier.toString(c.getModifiers()) + " class " + typename(c)); } Class[] interfaces = c.getInterfaces(); if ((interfaces != null) && (interfaces.length > 0)) { if (c.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 = c.getDeclaredConstructors(); for (int i = 0; i < constructors.length; i++) print_method_or_constructor(constructors[i]); Field[] fields = c.getDeclaredFields(); for (int i = 0; i < fields.length; i++) { print_field(fields[i]); } Method[] methods = c.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) print_method_or_constructor(methods[i]); System.out.println("}"); }
From source file:Main.java
public static <T extends Annotation> T getAnnotation(Class<?> clazz, Class<T> aClazz) { //Check class hierarchy for (Class<?> c = clazz; c != null; c = c.getSuperclass()) { T anno = c.getAnnotation(aClazz); if (anno != null) { return anno; }//from w w w . ja va 2s .c o m } //Check interfaces (breadth first) Queue<Class<?>> q = new LinkedList<Class<?>>(); q.add(clazz); while (!q.isEmpty()) { Class<?> c = q.remove(); if (c != null) { if (c.isInterface()) { T anno = c.getAnnotation(aClazz); if (anno != null) { return anno; } } else { q.add(c.getSuperclass()); } q.addAll(Arrays.asList(c.getInterfaces())); } } return null; }
From source file:org.cruxframework.crux.core.server.dispatch.Services.java
/** * Return the service that implements the interface informed. * @param interfaceName/*from w w w. ja v a2 s . com*/ * @return */ public static Class<?> getService(String interfaceName) { try { Set<String> serviceNames = ClassScanner.searchClassesByInterface(Class.forName(interfaceName)); if (serviceNames != null) { for (String service : serviceNames) { Class<?> serviceClass = Class.forName(service); if (!serviceClass.isInterface()) { return serviceClass; } } } logger.info("No implementation class found to service interface: [" + interfaceName + "]."); } catch (ClassNotFoundException e) { logger.error("Error creating service [" + interfaceName + "].", e); } return null; }
From source file:org.fusesource.meshkeeper.distribution.remoting.AbstractRemotingClient.java
protected static void validateInterface(Class<?> i) { if (!i.isInterface()) { throw new IllegalArgumentException("Not an interface: " + i); }//from www .java 2 s. co m }
From source file:org.datalorax.populace.core.populate.instance.DefaultTypeInstanceFactory.java
private static boolean isConcrete(final Class<?> rawType) { return !rawType.isInterface() && !Modifier.isAbstract(rawType.getModifiers()); }
From source file:Main.java
/** * Attempt to find a {@link Method} on the supplied class with the supplied name * and parameter types. Searches all superclasses up to <code>Object</code>. * <p>Returns <code>null</code> if no {@link Method} can be found. * * @param clazz the class to introspect * @param name the name of the method * @param paramTypes the parameter types of the method * (may be <code>null</code> to indicate any signature) * @return the Method object, or <code>null</code> if none found *//*w ww. j av a2 s .co m*/ public static Method findMethod(Class<?> clazz, String name, Class<?>... paramTypes) { Class<?> searchType = clazz; while (searchType != null) { Method[] methods = (searchType.isInterface() ? searchType.getMethods() : searchType.getDeclaredMethods()); for (Method method : methods) { if (name.equals(method.getName()) && (paramTypes == null || Arrays.equals(paramTypes, method.getParameterTypes()))) { return method; } } searchType = searchType.getSuperclass(); } return null; }