JVM中如何识别单例对象?
JVM 是否管理单例对象的任何特殊属性?我如何在我的程序中识别这一点?
Does JVM manage any special attribute for singleton object? How can I identify that in my program?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不会。堆中只有该特定类的一个实例。但同样,这并不一定意味着该类是单例类。它可以是一个仅实例化一次的普通类。
No. There would be just a single instance of that particular class in the heap. But again, it doesn't necessarily means that that class is a singleton. It can be a normal class just instantiated once.
我希望你指的是单例类的对象..我知道有一个单例类将确保只创建该类的一个实例..(即使在考虑反射、序列化-反序列化之后)我认为你不能考虑一个对象作为单例对象只是因为您没有找到同一类的任何其他对象。
I hope you meant singleton class's object.. I know there is singleton class which will make sure there is only one instance of that class ever created..(even after taking reflection, serialization-deserialization into consideration) I think you cannot consider an object as a singleton object just because you did not find any other object of the same class.