Agung
Agung

Reputation: 13873

why my class constructor is considered have the same declaration even though the data type is different?

so I have NotificationKM class like this

class NotificationKM() : Parcelable {

    var notificationID : String = ""
    var creatorID : String = ""
    var creatorName : String = ""
    var title : String = ""
    var body : String = ""
    var createdAt : Date = Calendar.getInstance().time
    var imagePath : String = ""
    var type : String = ""
    var hasBeenRead: Boolean = false


    constructor(dataMessage: MutableMap<String,Any>?) : this() {
        

    }

    constructor(data: MutableMap<String!,String!>) : this() {

    }

}

but I have an error:

Platform declaration clash: The following declarations have the same JVM signature

enter image description here

the data type is different, but I have this error. what should I do ?

Upvotes: 0

Views: 55

Answers (1)

Alexander Dadukin
Alexander Dadukin

Reputation: 564

Because generics in Java (and in Kotlin too as Kotlin produces jvm bytecode) are using type erasure mechanism, so, when your app will be compiled it would be only Map with no items type info. Also, nullability has no reflection at bytecode.

I would suggest creating 2 different factory methods with different names: createFromData and createFromMessage, for example

Upvotes: 1

Related Questions