If I use a private
field in my data class
, Firebase is unable to initialize it. Is it a bug or is this the intended behavior? Couldn't find anything in the documentation about it.
Asked
Active
Viewed 43 times
0

Olivér Raisz
- 353
- 3
- 12
-
3It uses JavaBeans conventions which requires public getters and setters. If your field is private, that means the getters and setters generated by kotlin will also be private. Also read: https://kotlinlang.org/docs/properties.html – Doug Stevenson Mar 12 '23 at 16:50
-
@DougStevenson Firebase doesn't necessarily require getters and setter, but it *does* require public access. So you can either have a public getter/setter for a field or mark the field itself as public. – Frank van Puffelen Mar 12 '23 at 16:58
-
1@FrankvanPuffelen Kotlin generates the getters and setters by default and doesn't expose publicly the "backing field" that actually holds the data (as discussed in the doc link above). This is a pretty big deviation from Java. – Doug Stevenson Mar 12 '23 at 17:06
-
Agreed. I just wanted to clarify that Firebase would take a public field too. – Frank van Puffelen Mar 12 '23 at 17:08