-1

I have a person object whose properties are initially null and through various stages object properties are populated, In javascript land I can have Object.assign which can create a new object without mutating the orignal object, Is there anything in java which can do the job for me. Key is immutability for me.

Prashanth
  • 107
  • 2
  • 12

1 Answers1

0

You need to create an immutable object in Java, read the documentation here:

https://docs.oracle.com/javase/tutorial/essential/concurrency/imstrat.html

For the Javascript Object.assign functionality, you can implement the Cloneable interface, there is however some discussion about that, so you might want to use a third party library like BeanUtils or SerializationUtils, as described in this answer:

About Java cloneable

Martijn Burger
  • 7,315
  • 8
  • 54
  • 94