lundi 8 janvier 2018

Check that the class implements the interface. Kotlin

I want check that the child class of SignalPayload implements the interface IConvertibleHow can I do that. :

sealed class SignalPayload {
    companion object {
        fun trueTypeInstance(type: KClass<SignalPayload>) : SignalPayload? {
          //  if (*** __ KClass<SignalPayload> implemented IConvertible ___  **) 
                ......

        }
    }
}
object Empty : SignalPayload()
data class BadData(val message: String = "BAD") : SignalPayload() {
    override fun toString(): String {
        return message
    }
}
data class payloadString(private var payload: String = "") : SignalPayload(), IConvertible
data class payloadInt(private var payload: Int = 0) : SignalPayload(), IConvertible
data class payloadFloat(private var payload: Float = 0F) : SignalPayload(), IConvertible
data class payloadBool(private var payload: Boolean = false) : SignalPayload(), IConvertible 

interface IConvertible {
    val asBool: Boolean
    val asInt: Int
    val asFloat: Float
    val asString: String
    fun setFromPayload(data: IConvertible)
}

How can I do that?





Aucun commentaire:

Enregistrer un commentaire