com.google.common.reflect.TypeToken.getGenericInterfaces()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(98)

本文整理了Java中com.google.common.reflect.TypeToken.getGenericInterfaces()方法的一些代码示例,展示了TypeToken.getGenericInterfaces()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TypeToken.getGenericInterfaces()方法的具体详情如下:
包路径:com.google.common.reflect.TypeToken
类名称:TypeToken
方法名:getGenericInterfaces

TypeToken.getGenericInterfaces介绍

[英]Returns the generic interfaces that this type directly implements. This method is similar but different from Class#getGenericInterfaces(). For example, newTypeToken>() {}.getGenericInterfaces()} will return a list that contains new TypeToken>() {}}; while List.class.getGenericInterfaces() will return an array that contains Iterable, where the T is the type variable declared by interface Iterable.

If this type is a type variable or wildcard, its upper bounds are examined and those that are either an interface or upper-bounded only by interfaces are returned. This means that the returned types could include type variables too.
[中]返回此类型直接实现的通用接口。此方法与类#getGenericInterfaces()类似但不同。例如,newTypeToken>({})。getGenericInterfaces()}将返回一个包含新TypeToken>(){}的列表;而不是列表。班getGenericInterfaces()将返回一个包含Iterable的数组,其中T是接口Iterable声明的类型变量。
如果该类型是类型变量或通配符,则会检查其上界,并返回接口或仅由接口上界的上界。这意味着返回的类型也可以包含类型变量。

代码示例

代码示例来源:origin: google/guava

@Override
Iterable<? extends TypeToken<?>> getInterfaces(TypeToken<?> type) {
 return type.getGenericInterfaces();
}

代码示例来源:origin: google/j2objc

@Override
Iterable<? extends TypeToken<?>> getInterfaces(TypeToken<?> type) {
 return type.getGenericInterfaces();
}

代码示例来源:origin: wildfly/wildfly

@Override
Iterable<? extends TypeToken<?>> getInterfaces(TypeToken<?> type) {
 return type.getGenericInterfaces();
}

代码示例来源:origin: google/guava

private static void assertHasArrayInterfaces(TypeToken<?> arrayType) {
 assertEquals(arrayInterfaces(), ImmutableSet.copyOf(arrayType.getGenericInterfaces()));
}

代码示例来源:origin: google/guava

public void testGetGenericInterfaces_wildcard_lowerBounded() {
 assertThat(TypeToken.of(Types.supertypeOf(String.class)).getGenericInterfaces()).isEmpty();
 assertThat(TypeToken.of(Types.supertypeOf(String[].class)).getGenericInterfaces()).isEmpty();
}

代码示例来源:origin: google/guava

public void testGetGenericInterfaces_wildcard_boundIsClass() {
 assertThat(TypeToken.of(Types.subtypeOf(Object.class)).getGenericInterfaces()).isEmpty();
 assertThat(TypeToken.of(Types.subtypeOf(Object[].class)).getGenericInterfaces()).isEmpty();
}

代码示例来源:origin: google/guava

public <T extends NoInterface, T1 extends T, T2 extends T1>
  void testGetGenericInterfaces_typeVariable_boundIsTypeVariableAndClass() {
 assertThat(TypeToken.of(new TypeCapture<T2>() {}.capture()).getGenericInterfaces()).isEmpty();
 assertHasArrayInterfaces(new TypeToken<T2[]>() {});
}

代码示例来源:origin: google/guava

public <T> void testGetGenericInterfaces_typeVariable_unbounded() {
 assertThat(TypeToken.of(new TypeCapture<T>() {}.capture()).getGenericInterfaces()).isEmpty();
 assertHasArrayInterfaces(new TypeToken<T[]>() {});
}

代码示例来源:origin: google/guava

public <T extends NoInterface> void testGetGenericInterfaces_typeVariable_boundIsClass() {
 assertThat(TypeToken.of(new TypeCapture<T>() {}.capture()).getGenericInterfaces()).isEmpty();
 assertHasArrayInterfaces(new TypeToken<T[]>() {});
}

代码示例来源:origin: google/guava

public <T extends CharSequence & Iterable<String>>
  void testGetGenericInterfaces_typeVariable_boundsAreInterfaces() {
 makeUnmodifiable(TypeToken.of(new TypeCapture<T>() {}.capture()).getGenericInterfaces())
   .containsExactly(TypeToken.of(CharSequence.class), new TypeToken<Iterable<String>>() {});
 assertHasArrayInterfaces(new TypeToken<T[]>() {});
}

代码示例来源:origin: google/guava

public <T extends CharSequence & Iterable<T>>
  void testGetGenericInterfaces_typeVariable_boundsAreFBoundedInterfaces() {
 makeUnmodifiable(TypeToken.of(new TypeCapture<T>() {}.capture()).getGenericInterfaces())
   .containsExactly(TypeToken.of(CharSequence.class), new TypeToken<Iterable<T>>() {});
 assertHasArrayInterfaces(new TypeToken<T[]>() {});
}

代码示例来源:origin: google/guava

public <T extends Iterable<T>, T1 extends T, T2 extends T1>
  void testGetGenericInterfaces_typeVariable_boundIsTypeVariableAndInterface() {
 makeUnmodifiable(TypeToken.of(new TypeCapture<T2>() {}.capture()).getGenericInterfaces())
   .containsExactly(TypeToken.of(new TypeCapture<T1>() {}.capture()));
 assertHasArrayInterfaces(new TypeToken<T2[]>() {});
}

代码示例来源:origin: google/guava

public <T extends NoInterface & Iterable<String>>
  void testGetGenericInterfaces_typeVariable_boundsAreClassWithInterface() {
 makeUnmodifiable(TypeToken.of(new TypeCapture<T>() {}.capture()).getGenericInterfaces())
   .containsExactly(new TypeToken<Iterable<String>>() {});
 assertHasArrayInterfaces(new TypeToken<T[]>() {});
}

代码示例来源:origin: google/guava

public <T extends Base & Iterable<T>>
  void testGetGenericInterfaces_typeVariable_boundsAreClassWithFBoundedInterface() {
 makeUnmodifiable(TypeToken.of(new TypeCapture<T>() {}.capture()).getGenericInterfaces())
   .containsExactly(new TypeToken<Iterable<T>>() {});
 assertHasArrayInterfaces(new TypeToken<T[]>() {});
}

代码示例来源:origin: google/guava

public void testGetGenericInterfaces_wildcard_boundIsInterface() {
 TypeToken<Iterable<String>> interfaceType = new TypeToken<Iterable<String>>() {};
 makeUnmodifiable(TypeToken.of(Types.subtypeOf(interfaceType.getType())).getGenericInterfaces())
   .containsExactly(interfaceType);
 assertHasArrayInterfaces(new TypeToken<Iterable<String>[]>() {});
}

代码示例来源:origin: com.google.guava/guava-tests

public <T extends NoInterface, T1 extends T, T2 extends T1>
void testGetGenericInterfaces_typeVariable_boundIsTypeVariableAndClass() {
 assertThat(TypeToken.of(new TypeCapture<T2>() {}.capture()).getGenericInterfaces()).isEmpty();
 assertHasArrayInterfaces(new TypeToken<T2[]>() {});
}

代码示例来源:origin: com.google.guava/guava-tests

public <T extends CharSequence&Iterable<T>>
void testGetGenericInterfaces_typeVariable_boundsAreFBoundedInterfaces() {
 makeUnmodifiable(TypeToken.of(new TypeCapture<T>() {}.capture()).getGenericInterfaces())
   .containsExactly(TypeToken.of(CharSequence.class), new TypeToken<Iterable<T>>() {});
 assertHasArrayInterfaces(new TypeToken<T[]>() {});
}

代码示例来源:origin: com.google.guava/guava-tests

public <T extends Iterable<T>, T1 extends T, T2 extends T1>
void testGetGenericInterfaces_typeVariable_boundIsTypeVariableAndInterface() {
 makeUnmodifiable(TypeToken.of(new TypeCapture<T2>() {}.capture()).getGenericInterfaces())
   .containsExactly(TypeToken.of(new TypeCapture<T1>() {}.capture()));
 assertHasArrayInterfaces(new TypeToken<T2[]>() {});
}

代码示例来源:origin: com.google.guava/guava-tests

public <T extends Base&Iterable<T>>
void testGetGenericInterfaces_typeVariable_boundsAreClassWithFBoundedInterface() {
 makeUnmodifiable(TypeToken.of(new TypeCapture<T>() {}.capture()).getGenericInterfaces())
   .containsExactly(new TypeToken<Iterable<T>>() {});
 assertHasArrayInterfaces(new TypeToken<T[]>() {});
}

代码示例来源:origin: com.google.guava/guava-tests

public void testGetGenericInterfaces_wildcard_boundIsInterface() {
 TypeToken<Iterable<String>> interfaceType = new TypeToken<Iterable<String>>() {};
 makeUnmodifiable(TypeToken.of(Types.subtypeOf(interfaceType.getType())).getGenericInterfaces())
   .containsExactly(interfaceType);
 assertHasArrayInterfaces(new TypeToken<Iterable<String>[]>() {});
}

相关文章

微信公众号

最新文章

更多

TypeToken类方法