Wesley Acheson
10/13/2020, 4:26 PMShawn
10/13/2020, 4:32 PMvalue
in this example supposed to be an instance of Class<*>
or are you attempting to match the type of value
in the when expression?Giorgos Neokleous
10/13/2020, 4:34 PMwhen (value) {
...
Enum.VALUE_ONE::class.java -> "A Enum Value 1"
Enum.VALUE_TWO::class.java -> "A Enum Value 2"
}
or
when (value) {
...
Enum::class.java -> value.enumConstants.first { it::class.java == value }.name
}
Shawn
10/13/2020, 4:36 PMvalue
is YourEnum::class.java
then I don’t believe you’ll be able to match against Enum::class.java
Wesley Acheson
10/13/2020, 4:37 PMval type: String = if (formatException.targetType == String::class.java) "a String"
else if (formatException.targetType == BigDecimal::class.java) "a Number"
else if (formatException.targetType == ZonedDateTime::class.java) "a Date"
else if (Enum::class.java.isAssignableFrom(formatException.targetType)) "a value of type ${formatException.targetType.simpleName}"
else formatException.targetType.simpleName
but I was hoping to change back to a when
when I got the values nailed down.
something like
val type: String = when {
formatException.targetType == String::class.java -> "a String"
formatException.targetType == BigDecimal::class.java -> "a Number"
formatException.targetType == ZonedDateTime::class.java -> "a Date"
Enum::class.java.isAssignableFrom(formatException.targetType) -> "a value of type ${formatException.targetType.simpleName}" // Possible values here.
else -> formatException.targetType.simpleName
}
Shawn
10/13/2020, 4:49 PMwhen
, but the ability to print all the possible values is entirely predicated on whether or not Jackson gives you a Class<*>
more specific than Class<Enum>
Wesley Acheson
10/13/2020, 5:21 PM