com.google.common.base.Enums.getField()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(2.0k)|赞(0)|评价(0)|浏览(181)

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

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));
}

相关文章