The question is that simple.
Kotlin documentation describes cloning only in accessing Java and in enum class. In latter case clone is just throwing an exception.
If the class you are trying to clone does not implement Cloneable
or is not a data class and is a part of an outside library, you can create an extension method that returns a new instance. For example:
class Person {
var id: String? = null
var name: String? = null
}
fun Person.clone(): Person {
val person = Person()
person.id = id
person.name = name
return person
}