本文整理了Java中com.google.common.base.Enums.getField()
方法的一些代码示例,展示了Enums.getField()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Enums.getField()
方法的具体详情如下:
包路径:com.google.common.base.Enums
类名称:Enums
方法名:getField
[英]Returns the Field in which enumValue is defined. For example, to get the Description annotation on the GOLF constant of enum Sport, use Enums.getField(Sport.GOLF).getAnnotation(Description.class).
[中]返回定义enumValue的字段。例如,要获取enum Sport的GOLF常量的描述注释,请使用enum。格特菲尔德(运动、高尔夫)。getAnnotation(Description.class)。
代码示例来源:origin: google/guava
@GwtIncompatible // reflection
public void testGetField() {
Field foo = Enums.getField(AnEnum.FOO);
assertEquals("FOO", foo.getName());
assertTrue(foo.isAnnotationPresent(ExampleAnnotation.class));
Field bar = Enums.getField(AnEnum.BAR);
assertEquals("BAR", bar.getName());
assertFalse(bar.isAnnotationPresent(ExampleAnnotation.class));
}
代码示例来源:origin: com.blackducksoftware.bdio/bdio-tinkerpop
private static Optional<Bdio.DataPropertyRange> dataRange(Bdio.DataProperty p) {
return Optional.ofNullable(Enums.getField(p).getAnnotation(Bdio.DataPropertyRange.class));
}
代码示例来源:origin: com.blackducksoftware.bdio/bdio-tinkerpop
private static Stream<Bdio.Domain> domain(Enum<?> e) {
Bdio.Domain domain = Enums.getField(e).getAnnotation(Bdio.Domain.class);
return domain != null ? Stream.of(domain) : Stream.empty();
}
代码示例来源:origin: com.blackducksoftware.bdio/bdio-tinkerpop
private static Stream<Bdio.ObjectPropertyRange> objectRange(Bdio.ObjectProperty p) {
Bdio.ObjectPropertyRange range = Enums.getField(p).getAnnotation(Bdio.ObjectPropertyRange.class);
return range != null ? Stream.of(range) : Stream.empty();
}
代码示例来源:origin: com.google.guava/guava-tests
@GwtIncompatible // reflection
public void testGetField() {
Field foo = Enums.getField(AnEnum.FOO);
assertEquals("FOO", foo.getName());
assertTrue(foo.isAnnotationPresent(ExampleAnnotation.class));
Field bar = Enums.getField(AnEnum.BAR);
assertEquals("BAR", bar.getName());
assertFalse(bar.isAnnotationPresent(ExampleAnnotation.class));
}
内容来源于网络,如有侵权,请联系作者删除!