本文整理了Java中java.lang.Class.isInterface()
方法的一些代码示例,展示了Class.isInterface()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Class.isInterface()
方法的具体详情如下:
包路径:java.lang.Class
类名称:Class
方法名:isInterface
[英]Tests whether this Class represents an interface.
[中]
代码示例来源:origin: google/guava
@Override
public boolean apply(TypeToken<?> type) {
return type.getRawType().isInterface();
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Set the interface of the service to access.
* The interface must be suitable for the particular service and remoting strategy.
* <p>Typically required to be able to create a suitable service proxy,
* but can also be optional if the lookup returns a typed proxy.
*/
public void setServiceInterface(Class<?> serviceInterface) {
Assert.notNull(serviceInterface, "'serviceInterface' must not be null");
Assert.isTrue(serviceInterface.isInterface(), "'serviceInterface' must be an interface");
this.serviceInterface = serviceInterface;
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Set the interface of the service to access.
* The interface must be suitable for the particular service and remoting tool.
* <p>Typically required to be able to create a suitable service proxy,
* but can also be optional if the lookup returns a typed stub.
*/
public void setServiceInterface(Class<?> serviceInterface) {
Assert.notNull(serviceInterface, "'serviceInterface' must not be null");
Assert.isTrue(serviceInterface.isInterface(), "'serviceInterface' must be an interface");
this.serviceInterface = serviceInterface;
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Set the interface that the proxy must implement.
* @param serviceInterface the interface that the proxy must implement
* @throws IllegalArgumentException if the supplied {@code serviceInterface}
* is not an interface type
*/
public void setServiceInterface(Class<?> serviceInterface) {
Assert.notNull(serviceInterface, "'serviceInterface' must not be null");
Assert.isTrue(serviceInterface.isInterface(), "'serviceInterface' must be an interface");
this.serviceInterface = serviceInterface;
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Set the interface of the service to export.
* The interface must be suitable for the particular service and remoting strategy.
*/
public void setServiceInterface(Class<?> serviceInterface) {
Assert.notNull(serviceInterface, "'serviceInterface' must not be null");
Assert.isTrue(serviceInterface.isInterface(), "'serviceInterface' must be an interface");
this.serviceInterface = serviceInterface;
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Set the interface of the service that this factory should create a proxy for.
*/
public void setServiceInterface(@Nullable Class<?> serviceInterface) {
if (serviceInterface != null) {
Assert.isTrue(serviceInterface.isInterface(), "'serviceInterface' must be an interface");
}
this.serviceInterface = serviceInterface;
}
代码示例来源:origin: apache/incubator-dubbo
private static void assertInterfaceArray(Class<?>[] ics) {
for (int i = 0; i < ics.length; i++) {
if (!ics[i].isInterface()) {
throw new RuntimeException("Class " + ics[i].getName() + " is not a interface.");
}
}
}
代码示例来源:origin: apache/incubator-dubbo
private static void assertInterfaceArray(Class<?>[] ics) {
for (int i = 0; i < ics.length; i++) {
if (!ics[i].isInterface()) {
throw new RuntimeException("Class " + ics[i].getName() + " is not a interface.");
}
}
}
代码示例来源:origin: square/retrofit
static <T> void validateServiceInterface(Class<T> service) {
if (!service.isInterface()) {
throw new IllegalArgumentException("API declarations must be interfaces.");
}
// Prevent API interfaces from extending other interfaces. This not only avoids a bug in
// Android (http://b.android.com/58753) but it forces composition of API declarations which is
// the recommended pattern.
if (service.getInterfaces().length > 0) {
throw new IllegalArgumentException("API interfaces must not extend other interfaces.");
}
}
代码示例来源:origin: spring-projects/spring-framework
public static Method findInterfaceMethod(Class iface) {
if (!iface.isInterface()) {
throw new IllegalArgumentException(iface + " is not an interface");
}
Method[] methods = iface.getDeclaredMethods();
if (methods.length != 1) {
throw new IllegalArgumentException("expecting exactly 1 method in " + iface);
}
return methods[0];
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Add the specified interface to the list of interfaces to introduce.
* @param intf the interface to introduce
*/
public void addInterface(Class<?> intf) {
Assert.notNull(intf, "Interface must not be null");
if (!intf.isInterface()) {
throw new IllegalArgumentException("Specified class [" + intf.getName() + "] must be an interface");
}
this.interfaces.add(intf);
}
代码示例来源:origin: google/guava
private ImmutableList<TypeToken<? super T>> boundsAsInterfaces(Type[] bounds) {
ImmutableList.Builder<TypeToken<? super T>> builder = ImmutableList.builder();
for (Type bound : bounds) {
@SuppressWarnings("unchecked") // upper bound of T
TypeToken<? super T> boundType = (TypeToken<? super T>) of(bound);
if (boundType.getRawType().isInterface()) {
builder.add(boundType);
}
}
return builder.build();
}
代码示例来源:origin: spring-projects/spring-framework
public ReflectiveElementFactory(Class<? extends E> elementClass) {
Assert.notNull(elementClass, "Element class must not be null");
Assert.isTrue(!elementClass.isInterface(), "Element class must not be an interface type");
Assert.isTrue(!Modifier.isAbstract(elementClass.getModifiers()), "Element class cannot be an abstract class");
this.elementClass = elementClass;
}
代码示例来源:origin: google/guava
private @Nullable TypeToken<? super T> boundAsSuperclass(Type bound) {
TypeToken<?> token = of(bound);
if (token.getRawType().isInterface()) {
return null;
}
@SuppressWarnings("unchecked") // only upper bound of T is passed in.
TypeToken<? super T> superclass = (TypeToken<? super T>) token;
return superclass;
}
代码示例来源:origin: apache/incubator-dubbo
public void setInterface(Class<?> interfaceClass) {
if (interfaceClass != null && !interfaceClass.isInterface()) {
throw new IllegalStateException("The interface class " + interfaceClass + " is not a interface!");
}
this.interfaceClass = interfaceClass;
setInterface(interfaceClass == null ? null : interfaceClass.getName());
}
代码示例来源:origin: apache/incubator-dubbo
public void setInterface(Class<?> interfaceClass) {
if (interfaceClass != null && !interfaceClass.isInterface()) {
throw new IllegalStateException("The interface class " + interfaceClass + " is not a interface!");
}
this.interfaceClass = interfaceClass;
setInterface(interfaceClass == null ? null : interfaceClass.getName());
}
代码示例来源:origin: google/guava
@Override
ImmutableList<K> collectTypes(Iterable<? extends K> types) {
ImmutableList.Builder<K> builder = ImmutableList.builder();
for (K type : types) {
if (!getRawType(type).isInterface()) {
builder.add(type);
}
}
return super.collectTypes(builder.build());
}
};
代码示例来源:origin: google/guava
private <T> T defaultGenerate(Class<T> rawType) {
if (rawType.isInterface()) {
// always create a new proxy
return newProxy(rawType);
}
return ArbitraryInstances.get(rawType);
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public <T> T getExtension(Class<T> type, String name) {
if (type.isInterface() && type.isAnnotationPresent(SPI.class)) {
ExtensionLoader<T> loader = ExtensionLoader.getExtensionLoader(type);
if (!loader.getSupportedExtensions().isEmpty()) {
return loader.getAdaptiveExtension();
}
}
return null;
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public <T> T getExtension(Class<T> type, String name) {
if (type.isInterface() && type.isAnnotationPresent(SPI.class)) {
ExtensionLoader<T> loader = ExtensionLoader.getExtensionLoader(type);
if (!loader.getSupportedExtensions().isEmpty()) {
return loader.getAdaptiveExtension();
}
}
return null;
}
内容来源于网络,如有侵权,请联系作者删除!