juangamnik
07/16/2016, 2:58 PMinline fun <reified T: Action>T.reversedAction(): T {
// If I do not use the constant `me` here, but `this`, `this`
// would be smart casted to `TemporalAction`, but *loose* its type `T`
// but it should have both then!
val me = this
return when (me) {
is TemporalAction -> {
val copy = this.copy()
(copy as TemporalAction).isReverse = !copy.isReverse
copy
}
// other cases
else -> this
}
}
I would like to be able to do it like this:
inline fun <reified T: Action>T.reversedAction(): T {
return when (this) {
is TemporalAction -> {
val copy = this.copy()
copy.isReverse = !copy.isReverse
copy
}
// other cases
else -> this
}
}