https://kotlinlang.org logo
#getting-started
Title
# getting-started
c

chansek

03/29/2022, 6:04 PM
Any possibility to make the below code compilable:
Copy code
abstract class SomeLibraryClass<T> {
    abstract fun test(key: String): T
}

class Item<T : Enum<T>> : SomeLibraryClass<T>() {
    override fun test(key: String): T {
        return enumValueOf(key)
    }
}
Can't make T as
reified
or
test
as inline. How can I inherit the library class for enum?
c

Cedrick Cooke

03/29/2022, 8:22 PM
Something like this would work. The
companion object
is totally optional, but it allows constructing via
Item<Foobar>()
instead of
Item(Foobar::class.java)
c

chansek

03/30/2022, 6:22 AM
Thanks Cedrick 👍
3 Views