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). @since 12.0
(Enum<?> enumValue)
| 50 | */ |
| 51 | |
| 52 | @GwtIncompatible // reflection |
| 53 | public static Field getField(Enum<?> enumValue) { |
| 54 | Class<?> clazz = enumValue.getDeclaringClass(); |
| 55 | try { |
| 56 | return clazz.getDeclaredField(enumValue.name()); |
| 57 | } catch (NoSuchFieldException impossible) { |
| 58 | throw new AssertionError(impossible); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Returns an optional enum constant for the given type, using {@link Enum#valueOf}. If the |
no test coverage detected