Do effectively immutable objects make sense?

后端 未结 4 1981
广开言路
广开言路 2021-02-20 16:24

In the book Java Concurrency In Practice it explains the advantages of \"effectively immutable\" objects versus mutable objects concurrency-wise. But it does not explain what a

4条回答
  •  名媛妹妹
    2021-02-20 17:00

    Yes, they make sense in some cases. An easy example is when you want some property to be generated lazily and cached so you can avoid the overhead of generating it if it's never accessed. String is an example of an effectively immutable class that does this (with its hashcode).

提交回复
热议问题