another question
I have an interface Measure, with an abstract function convert(target: Measure)
I have three enum classes (Length, Weight, Temperature) that implement the interface and override the convert() function
I also have a String.toMeasure() extension function that parses a string as an enum of one of three classes and returns a Measure object
I want each enum class to be able to convert only to another enum of the same class
There are two ways to do it
1) make the convert() function take an argument of type Measure, then check if the target is of the same enum class as the source, else throw exception
the downside here is that each overridden implementation of this function needs to check if source and target are of the same class (otherwise the "when" is not exhaustive)
I'd like to localize the check to one place
2) I declare interface Measure<T>, with an abstract function convert(target: T)
and I declare my enum classes as Length : Measure<Length>, etc
this way, each enum can only convert to another enum of the same class
however, this is where I get a problem with the toMeasure() function
it used to return a Measure object, but now it needs to return Measure<something>
continued it thread...