Vitali Plagov
04/21/2020, 11:33 AMVitali Plagov
04/21/2020, 11:34 AMcompanion object {
fun methodByValue(value: String) = values().first { it.value == methodValue }
}
marstran
04/21/2020, 11:37 AMEnumCompanion
interface though.
interface EnumCompanion<T : Enum<T>>
enum class Test {
A, B, C;
companion object : EnumCompanion<Test>
}
fun EnumCompanion<Test>.print() = print(this)
fun main() {
Test.print()
}
marstran
04/21/2020, 11:39 AMVitali Plagov
04/21/2020, 11:44 AMmarstran
04/21/2020, 11:48 AMmarstran
04/21/2020, 11:51 AMVitali Plagov
04/21/2020, 11:52 AMfun EnumCompanion<Test>.print() = print(this)
. Where is it located?marstran
04/21/2020, 11:52 AMfun <T> EnumCompanion<T>.methodByValue(value: String) = TODO()
Vitali Plagov
04/21/2020, 12:34 PMfun <T> EnumCompanion<T>.methodByValue(value: String) = this.values().first { it.value == methodValue }
It doesn’t compilemarstran
04/21/2020, 1:14 PMenumValues<T>()
, and that requires T
to be reified. Look that the definition of getByKey
in my Stack Overflow answer.marstran
04/21/2020, 1:15 PMit.value
will not compile, because the generic T
doesn't have value
defined.Vitali Plagov
04/21/2020, 1:16 PMvalue
?marstran
04/21/2020, 1:17 PMval T.key: K
inside the EnumWithKey
interface.Vitali Plagov
04/21/2020, 1:19 PMDavid Eriksson
04/21/2020, 2:06 PMfun KClass<MyEnum>.MyExtensionFunction()
so that it could be called as MyEnum::class.MyExtensionFunction()
?marstran
04/21/2020, 2:11 PMDavid Eriksson
04/21/2020, 2:12 PMDavid Eriksson
04/21/2020, 2:12 PMmarstran
04/21/2020, 2:13 PMimport kotlin.reflect.KClass
😉David Eriksson
04/21/2020, 2:15 PM