I have read that immutable object can be cached and reused in java and this is one of the advantage of using immutable object. My question is what's in java responsible for caching immutable object. Where is this logic written in java?
Asked
Active
Viewed 53 times
0
-
does this answer to your question https://stackoverflow.com/questions/6305752/how-to-create-immutable-objects-in-java – Nitin Singhal Jun 25 '20 at 06:40
-
1It happens because you write code that caches and reuses them. The point is that this can be done *safely*, because there is no risk of two threads corrupting the state of instances they are both using. – Andy Turner Jun 25 '20 at 06:53