If you need instances, that sounds more like seale...
# getting-started
s
If you need instances, that sounds more like sealed classes than enums
n
I don’t need instances per se, but that’s how enum entries are represented in Kotlin anyhow.
s
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
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
@Shawn This is correct.