https://kotlinlang.org logo
Title
s

Shawn

11/12/2018, 4:04 PM
If you need instances, that sounds more like sealed classes than enums
n

nestserau

11/12/2018, 4:05 PM
I don’t need instances per se, but that’s how enum entries are represented in Kotlin anyhow.
s

Shawn

11/12/2018, 4:13 PM
I’m kinda just asking for my own benefit at this point, but I’m curious what the use case is for an interface that mandates classes themselves provide a method but not the class instances
assuming I’m interpreting the problem correctly - that you want, for example, your own
DayOfWeek
enum to have a
fromInt()
method on it
like do you plan on operating on collections of these types?
List<HasFromInt>
or something similar?
k

karelpeeters

11/12/2018, 4:42 PM
It's pretty easy to write function like this btw, just have a parameter in the enum constructor and then in the companion object
fun fromInt(int: Int) = MyEnum.values.first { it.day == int }
1
But that's not generic of course.
n

nestserau

11/13/2018, 7:58 AM
@Shawn This is correct.