本文整理了Java中java.lang.Class.getInterfaces()
方法的一些代码示例,展示了Class.getInterfaces()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Class.getInterfaces()
方法的具体详情如下:
包路径:java.lang.Class
类名称:Class
方法名:getInterfaces
[英]Returns an array of Class objects that match the interfaces in the implements declaration of the class represented by this Class. The order of the elements in the array is identical to the order in the original class declaration. If the class does not implement any interfaces, an empty array is returned.
[中]返回与该类所表示的类的implements声明中的接口匹配的类对象数组。数组中元素的顺序与原始类声明中的顺序相同。如果该类未实现任何接口,则返回空数组。
代码示例来源:origin: libgdx/libgdx
static public Class[] getInterfaces(Class c) {
return c.getInterfaces();
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public String[] getInterfaceNames() {
Class<?>[] ifcs = this.introspectedClass.getInterfaces();
String[] ifcNames = new String[ifcs.length];
for (int i = 0; i < ifcs.length; i++) {
ifcNames[i] = ifcs[i].getName();
}
return ifcNames;
}
代码示例来源:origin: google/guava
@Override
Iterable<? extends Class<?>> getInterfaces(Class<?> type) {
return Arrays.asList(type.getInterfaces());
}
代码示例来源:origin: google/guava
private static boolean isProxyOfSameInterfaces(Object arg, Class<?> proxyClass) {
return proxyClass.isInstance(arg)
// Equal proxy instances should mostly be instance of proxyClass
// Under some edge cases (such as the proxy of JDK types serialized and then deserialized)
// the proxy type may not be the same.
// We first check isProxyClass() so that the common case of comparing with non-proxy objects
// is efficient.
|| (Proxy.isProxyClass(arg.getClass())
&& Arrays.equals(arg.getClass().getInterfaces(), proxyClass.getInterfaces()));
}
}
代码示例来源: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
@Nullable
private static List<Method> findConcreteMethodsOnInterfaces(Class<?> clazz) {
List<Method> result = null;
for (Class<?> ifc : clazz.getInterfaces()) {
for (Method ifcMethod : ifc.getMethods()) {
if (!Modifier.isAbstract(ifcMethod.getModifiers())) {
if (result == null) {
result = new ArrayList<>();
}
result.add(ifcMethod);
}
}
}
return result;
}
代码示例来源:origin: spring-projects/spring-framework
public static List addAllInterfaces(Class type, List list) {
Class superclass = type.getSuperclass();
if (superclass != null) {
list.addAll(Arrays.asList(type.getInterfaces()));
addAllInterfaces(superclass, list);
}
return list;
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Determine whether the given interface is just a container callback and
* therefore not to be considered as a reasonable proxy interface.
* <p>If no reasonable proxy interface is found for a given bean, it will get
* proxied with its full target class, assuming that as the user's intention.
* @param ifc the interface to check
* @return whether the given interface is just a container callback
*/
protected boolean isConfigurationCallbackInterface(Class<?> ifc) {
return (InitializingBean.class == ifc || DisposableBean.class == ifc || Closeable.class == ifc ||
AutoCloseable.class == ifc || ObjectUtils.containsElement(ifc.getInterfaces(), Aware.class));
}
代码示例来源:origin: spring-projects/spring-framework
private void addInterfacesToClassHierarchy(Class<?> type, boolean asArray,
List<Class<?>> hierarchy, Set<Class<?>> visited) {
for (Class<?> implementedInterface : type.getInterfaces()) {
addToClassHierarchy(hierarchy.size(), implementedInterface, asArray, hierarchy, visited);
}
}
代码示例来源:origin: spring-projects/spring-framework
public Type[] getInterfaces() {
return TypeUtils.getTypes(clazz.getInterfaces());
}
public int getModifiers() {
代码示例来源:origin: greenrobot/EventBus
/** Recurses through super interfaces. */
static void addInterfaces(List<Class<?>> eventTypes, Class<?>[] interfaces) {
for (Class<?> interfaceClass : interfaces) {
if (!eventTypes.contains(interfaceClass)) {
eventTypes.add(interfaceClass);
addInterfaces(eventTypes, interfaceClass.getInterfaces());
}
}
}
代码示例来源:origin: spring-projects/spring-framework
private List<Annotation[][]> getInterfaceParameterAnnotations() {
List<Annotation[][]> parameterAnnotations = this.interfaceParameterAnnotations;
if (parameterAnnotations == null) {
parameterAnnotations = new ArrayList<>();
for (Class<?> ifc : this.method.getDeclaringClass().getInterfaces()) {
for (Method candidate : ifc.getMethods()) {
if (isOverrideFor(candidate)) {
parameterAnnotations.add(candidate.getParameterAnnotations());
}
}
}
this.interfaceParameterAnnotations = parameterAnnotations;
}
return parameterAnnotations;
}
代码示例来源:origin: spring-projects/spring-framework
public static List addAllMethods(final Class type, final List list) {
if (type == Object.class) {
list.addAll(OBJECT_METHODS);
}
else
list.addAll(java.util.Arrays.asList(type.getDeclaredMethods()));
Class superclass = type.getSuperclass();
if (superclass != null) {
addAllMethods(superclass, list);
}
Class[] interfaces = type.getInterfaces();
for (int i = 0; i < interfaces.length; i++) {
addAllMethods(interfaces[i], list);
}
return list;
}
代码示例来源:origin: spring-projects/spring-framework
@Nullable
private static Method searchInterfaces(Class<?>[] interfaces, Method bridgeMethod) {
for (Class<?> ifc : interfaces) {
Method method = searchForMatch(ifc, bridgeMethod);
if (method != null && !method.isBridge()) {
return method;
}
else {
method = searchInterfaces(ifc.getInterfaces(), bridgeMethod);
if (method != null) {
return method;
}
}
}
return null;
}
代码示例来源:origin: jenkinsci/jenkins
private static boolean isSuperTypesStaplerRelevant(@Nonnull Class<?> clazz) {
Class<?> superclass = clazz.getSuperclass();
if (superclass != null && isStaplerRelevantCached(superclass)) {
return true;
}
for (Class<?> interfaceClass : clazz.getInterfaces()) {
if (isStaplerRelevantCached(interfaceClass)) {
return true;
}
}
return false;
}
代码示例来源:origin: spring-projects/spring-framework
public Set<SourceClass> getInterfaces() throws IOException {
Set<SourceClass> result = new LinkedHashSet<>();
if (this.source instanceof Class) {
Class<?> sourceClass = (Class<?>) this.source;
for (Class<?> ifcClass : sourceClass.getInterfaces()) {
result.add(asSourceClass(ifcClass));
}
}
else {
for (String className : this.metadata.getInterfaceNames()) {
result.add(asSourceClass(className));
}
}
return result;
}
代码示例来源:origin: org.mockito/mockito-core
private void addInterfaces(Set<Class<?>> types, Class<?>[] interfaces) {
for (Class<?> type : interfaces) {
if (mocked.add(type)) {
types.add(type);
addInterfaces(types, type.getInterfaces());
}
}
}
代码示例来源:origin: spring-projects/spring-framework
private void introspectInterfaces(Class<?> beanClass, Class<?> currClass) throws IntrospectionException {
for (Class<?> ifc : currClass.getInterfaces()) {
if (!ClassUtils.isJavaLanguageInterface(ifc)) {
for (PropertyDescriptor pd : getBeanInfo(ifc).getPropertyDescriptors()) {
PropertyDescriptor existingPd = this.propertyDescriptorCache.get(pd.getName());
if (existingPd == null ||
(existingPd.getReadMethod() == null && pd.getReadMethod() != null)) {
// GenericTypeAwarePropertyDescriptor leniently resolves a set* write method
// against a declared read method, so we prefer read method descriptors here.
pd = buildGenericTypeAwarePropertyDescriptor(beanClass, pd);
this.propertyDescriptorCache.put(pd.getName(), pd);
}
}
introspectInterfaces(ifc, ifc);
}
}
}
代码示例来源:origin: google/guava
private static ImmutableSet<TypeToken<?>> arrayInterfaces() {
ImmutableSet.Builder<TypeToken<?>> builder = ImmutableSet.builder();
for (Class<?> interfaceType : Object[].class.getInterfaces()) {
builder.add(TypeToken.of(interfaceType));
}
return builder.build();
}
代码示例来源:origin: google/guava
public <T, T1 extends T> void testAssignableGenericArrayToClass() {
assertTrue(TypeToken.of(Object[].class.getSuperclass()).isSupertypeOf(new TypeToken<T[]>() {}));
for (Class<?> interfaceType : Object[].class.getInterfaces()) {
assertTrue(TypeToken.of(interfaceType).isSupertypeOf(new TypeToken<T[]>() {}));
}
assertTrue(TypeToken.of(Object.class).isSupertypeOf(new TypeToken<T[]>() {}));
assertFalse(TypeToken.of(String.class).isSupertypeOf(new TypeToken<T[]>() {}));
}
内容来源于网络,如有侵权,请联系作者删除!