Enumerable
Java's Enums are infuriating. If you have an instance of an Enum, there is no way to enumerate all possible values. Isn't that ironic given 'Enum' is short for enumeration. You need the Enum's type (at compile-time, which Kyd doesn't have)
This is my workaround. Any enums that you use as @Custom properties must implement this interface. For example :
enum class Foo : Enumerable {
ITEM1, ITEM2;
override fun enumerateValues() = Foo.entries()
}
Content copied to clipboard
Then declare your property :
val myFooProperty by property( Foo.ITEM1 )
var myFoo by myFooProperty
Content copied to clipboard
NOTE. This solution isn't perfect; I had to use @Suppress("UNCHECKED_CAST"). It will break if you do something like this :
enum class Foo : Enumerable { ... }
Content copied to clipboard
I don't see a way to prevent this. I want to define Enumerable like so :
interface Enumerable : Enum
Content copied to clipboard
But that's not possible, because Enum is a class, not an interface. Java's Enums are infuriating.