Not sure whether it’s been discussed (didn’t find related threads in this forum). My use case is that I define some nested data structure (using data class) and some of them is declared as object. Then I use jackson to serialize/deserialize it for persistence. When I deserialize an instance of this data type, I realize those object declarations are not really singletons and their heap id is different. I could workaround this by making those object as data class but maybe it’s worthing mentioning this behavior in the document to avoid any misunderstanding. By the way, I find a similar discussion on the web: Not so Singletons in Kotlin. Putting Kotlin’s Object Declaration to… | by Rahul Chowdhury | AndroidPub | Medium
Related topics
| Topic | Replies | Views | Activity | |
|---|---|---|---|---|
| How did Kotlin design Object so that deserialization still only exists as a singleton | 1 | 148 | November 3, 2024 | |
|
Finding a singleton via reflection
|
4 | 2566 | September 23, 2016 | |
| Singleton with object declarations gets garbage collected | 10 | 10442 | October 2, 2017 | |
| Serializing singleton-objects using Gson | 1 | 3192 | August 9, 2016 | |
|
6.179 & singletons (object classes)
|
1 | 952 | September 2, 2013 |