https://kotlinlang.org logo
#codereview
Title
# codereview
h

hho

05/25/2021, 4:56 PM
Is there a better (or "more Kotlin") way to get an enum value when I don't have a concrete type? It feels weird having to resort to
java.lang.Enum
...
Copy code
sealed class EnumBinding<E : Enum<E>>(
	private val enumType: Class<E>
) : Binding<Any?, E?> {

	override fun converter(): Converter<Any?, E?> = object : Converter<Any?, E?> {
		override fun from(databaseObject: Any?): E? =
			databaseObject?.let { java.lang.Enum.valueOf(enumType, it.toString()) }
        …
    }
    …
}
(it's a custom jOOQ binding, so I can't change
Binding
or
Converter
)
tl;dr ideally there would be, and there's a feature request, but for now there's no way to it without Java reflection
h

hho

05/25/2021, 5:59 PM
Thank you! Upvoted. (but 5 years already … 😟)
m

Matteo Mirk

05/26/2021, 9:03 AM
h

hho

05/26/2021, 9:13 AM
no, because you can't write a concrete type for
T
m

Matteo Mirk

05/26/2021, 9:22 AM
I see, thanks