Enumerable

interface Enumerable<T : Enum<T>>

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()
}

Then declare your property :

val myFooProperty by property( Foo.ITEM1 )
var myFoo by myFooProperty

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 { ... }

I don't see a way to prevent this. I want to define Enumerable like so :

interface Enumerable : Enum

But that's not possible, because Enum is a class, not an interface. Java's Enums are infuriating.

Properties

Link copied to clipboard
abstract val name: String

You won't need to implement this, because it is part of Enum.

Functions

Link copied to clipboard
abstract fun enumerateValues(): List<Enumerable<T>>