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
Shawn
11/12/2018, 4:13 PM
assuming I’m interpreting the problem correctly - that you want, for example, your own
DayOfWeek
enum to have a
fromInt()
method on it
Shawn
11/12/2018, 4:15 PM
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 }