louiscad
07/01/2020, 8:15 AMenum ThatEnum(val thatProperty: Float) {
FirstEntry(thatProperty = 10),
AnotherEntry(thatProperty = 20),
LastEntry(thatProperty = Float.POSITIVE_INFINITY);
companion object {
init {
check(values().contentEquals(values().apply { sortBy { it.thatProperty } }))
}
}
}
That requires to companion object
to be accessed for the check to execute, which is fine in my case since I use it to get instances of the enum early.Ashish Kumar Joy
07/01/2020, 8:23 AMlouiscad
07/01/2020, 8:24 AMpedro
07/01/2020, 8:24 AMfold
instead. (Check that the property monotonically increases.)louiscad
07/01/2020, 8:24 AMMatteo Mirk
07/01/2020, 8:32 AMlouiscad
07/01/2020, 8:34 AMfold
.