Kotlin can't do this, or is the syntax wrong? Does...
# compiler
r
Kotlin can't do this, or is the syntax wrong? Doesn't know
T
in the inner object.
Copy code
@Serializable
sealed interface Request<T> {
    data object Get
    data class Set(val value: T) : ReturnValue
}
d
Only
inner
classes can catch type parameters of containing classes as each specific object will have it's own actual parametrization
Set
class in your example is not
inner
, but nested class
r
Ah ok, and then it can't be an interface, but needs to be an actual class etc, so probably more trouble than it's worth
y
Are Get and Set meant to be implementations of
Request
? If so, the solution is simple:
Copy code
@Serializable
sealed interface Request<out T> {
    data object Get: Request<Nothing>
    data class Set<out T>(val value: T) : ReturnValue, Request<T>
}
r
More of a thought experiment, the actual API's gotta be different 😭
y
inner class
is a very specific OOP concept. The closest general Kotlin feature would be something like
context(...) class
(which is getting removed lol). What you likely want is something akin to this:
Copy code
@Serializable
sealed interface Request<T> {
    data object Get
    data class Set<T>(val request: Request<T>, val value: T) : ReturnValue
}
But as you can see, this is useless since rn there's no implementors of
Request