Is it correct that, currently, we can't create inl...
# announcements
m
Is it correct that, currently, we can't create inline classes that implement Comparable<T>?
e
Why? What kind of error are you getting?
m
I'm getting the following exception at runtime:
Copy code
Caused by: java.lang.ClassCastException: class com.aeyeonmovement.FrameIndex cannot be cast to class java.lang.Number (com.aeyeonmovement.FrameIndex is in unnamed module of loader 'app'; java.lang.Number is in module java.base of loader 'bootstrap')
This is a piece of stack trace:
Copy code
Exception in thread "JavaFX Application Thread @coroutine#15" java.lang.ClassCastException: class com.aeyeonmovement.FrameIndex cannot be cast to class java.lang.Number (com.aeyeonmovement.FrameIndex is in unnamed module of loader 'app'; java.lang.Number is in module java.base of loader 'bootstrap')
	at com.aeyeonmovement.FrameIndex.next-t4yMDwI(FrameIndex.kt:7)
	at com.aeyeonmovement.FrameIndexRange$Iterator.next-t4yMDwI(FrameIndexRange.kt:60)
	at com.aeyeonmovement.FrameIndexRange$Iterator.next(FrameIndexRange.kt:55)
Ok. It does not seem to be related to the Comparable interface. It happens, when the method
next()
is called.
FrameIndex
implements
Index<FrameIndex>
which is defined as:
Copy code
interface Index<T> : Comparable<T> {
    val value : Int

    val number get() = value + 1

    val isStrictlyNegative get() =
        value < 0
    val isPositive get() =
        value >= 0

    val isOdd: Boolean get() = value % 2 != 0

    operator fun plus(n : Int) : T
    operator fun minus(n : Int) : T

    fun next() : T = this + 1
    fun previous() : T = this - 1

    val parity get() = Parity.of(value)
}
That
next()
method is the one that is called.
I still don't understand why
FrameIndex
needs to be cast to
Number
.