I'm working with an immutable data-structure in Java and am getting mildly annoyed, by the tedious work of copying each object when I want to change the properties of them.
I know in Kotlin this can be done easily with the data-classes .copy()
function. And I want to know if there is the same function in Java? Maybe over some library?
Something that would allow stuff like this:
Implementation:
fun copy(name: String = this.name, age: Int = this.age) = User(name, age)
Usage:
val jack = User(name = "Jack", age = 1)
val olderJack = jack.copy(age = 2)
Thanks for your help ^^