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 | |
---|---|---|---|---|
Serializing singleton-objects using Gson | 1 | 3074 | August 9, 2016 | |
Finding a singleton via reflection
|
4 | 2444 | September 23, 2016 | |
Singleton with object declarations gets garbage collected | 10 | 10113 | October 2, 2017 | |
Can I create a data class at run-time? | 9 | 14568 | September 7, 2019 | |
What's the kotlin-way to create a instance dynamically?
|
1 | 11371 | October 15, 2012 |