How to convert Java object to a Kotlin Multi Platform object

312 Views Asked by At

I have a Java object. And I have a Kotlin Multi Platform object. How do I convert this Java object to the Kotlin Multi Platform object?

Java Code:

public class JavaRecentItemList extends ObservableBean implements Parcelable {

    @SerializedName("TotalRowCount")
    int totalRowCount;
}

Kotlin Multi Platform Shared code:

import kotlinx.serialization.Serializable

@Serializable
data class KMMRecentItemList(
    val TotalRowCount: Int? = null
)

I have a KMM library that needs a KMMRecentItemList. i.e:

suspend fun foo(itemList: KMMRecentItemList) {
}
1

There are 1 best solutions below

1
On BEST ANSWER

You just copy it the straightforward way. Nothing is special about these objects from Kotlin's perspective.

 val converted = KMMREcentItemList(javaRecentItemList.totalRowCount)