Are all immutable objects singleton instances? [closed]

泪湿孤枕 提交于 2019-12-13 11:16:44

问题


Are all immutable objects singleton instances?


回答1:


No.

Immutable objects are unchangeable, the normal practice for these is to pass (inject) all required values via the constructor (i.e. they are specified when the object is instantiated), these are then externally unchangeable for the lifetime of the object.

Singleton objects are when there is a single instance, that instance could be immutable but seldom is.



来源:https://stackoverflow.com/questions/13784244/are-all-immutable-objects-singleton-instances

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!