Can I express this code without having to have the...
# getting-started
r
Can I express this code without having to have the
TLV<T>
signature, and just use
TLV
to represent it, if I'm using the interface to designate the type?
Copy code
sealed interface TLV<T> {
    val value: T
    val type: Byte
}
object TLVNULL: TLV<Unit> {
    override val type: Byte = 0x00
    override val value: Unit = Unit
}
data class TLVNDEF(override val value: NdefMessage): TLV<NdefMessage> {
    override val type: Byte = 0x03
}
data class TLVProp(override val value: ByteArray): TLV<ByteArray> {
    override val type: Byte = 0xFD.toByte()
}
object TLVTerminator: TLV<Unit> {
    override val type: Byte = 0xFE.toByte()
    override val value: Unit = Unit
}
y
Remove the
<T>
and the
val value: T
inside the interface. Then, you'll only have access to the value if you know which subclass of
TLV
you have. I think that leaving it as-is could be a better design though.