Package com.google.common.base
Class Enums
-
- com.google.common.base.Enums
-
@GwtCompatible(emulated=true) public final class Enums extends
Utility methods for working with instances.- Since:
- 9.0
- Author:
- Steve McKay
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static
<?> enumValue)
Returns the in whichenumValue
is defined.static <T extends <T>>
Optional<T><T> enumClass, value)
Returns an optional enum constant for the given type, using .static <T extends <T>>
,T><T> enumClass)
Returns a converter that converts between strings andenum
values of typeenumClass
using and .
-
-
-
Method Detail
-
getField
@GwtIncompatible public static <?> enumValue)
Returns the in whichenumValue
is defined. For example, to get theDescription
annotation on theGOLF
constant of enumSport
, useEnums.getField(Sport.GOLF).getAnnotation(Description.class)
.- Since:
- 12.0
-
getIfPresent
public static <T extends <T>> <T> enumClass, value)
Returns an optional enum constant for the given type, using . If the constant does not exist,Optional.absent()
is returned. A common use case is for parsing user input or falling back to a default enum constant. For example,Enums.getIfPresent(Country.class, countryInput).or(Country.DEFAULT);
- Since:
- 12.0
-
stringConverter
public static <T extends <T>> ,T> <T> enumClass)
Returns a converter that converts between strings andenum
values of typeenumClass
using and . The converter will throw anIllegalArgumentException
if the argument is not the name of any enum constant in the specified enum.- Since:
- 16.0
-
-