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.
Asked
Active
Viewed 572 times
-1
-
Please specify the reason for negative ratings?. – Prashanth Feb 22 '18 at 19:43
-
Have you tried cloning the object? – fubar Feb 22 '18 at 21:52
-
1Try to add more details and code examples. That makes the question much clearer and you will be more likely to get an answer! – Peter J Feb 22 '18 at 22:03
1 Answers
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:

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