Thanks, that helps to get rid of the warning. I am still wondering if there is a way to call java.lang.Enum.valueOf(class, name) with Kotlin generics (instead of raw classes in java) with a class where the enum type in generic is not known.
Do you need this function to receive any possible Class or only classes that are verified at compile time to be enums? I ask because your original Java code could receive e.g. Class<String>, but your Kotlin equivalent does not.
If enum requirement is fine, then I believe the proper solution is like this:
fun <T : Enum<T>> getEnumValue(enumClass: Class<T>, value: String): T {
return java.lang.Enum.valueOf(enumClass, value)
}
But I’m not sure if this helps you match, because if you are using Class<Enum<*>> currently, then you will probably have exactly the same problem executing this above function as you have problem executing Enum.valueOf() right now.
Hi, no, I need it to receive any possible Class as you wrote, I cannot do <T : Enum<T>> - on the input I only have value type as KClass<*> and a String value - depending on a class it’s trying to convert the String value to appropriate type, e.g. Double, BigDecimal, Enum, ZonedDateTime…