I think most people would choose to use #1 or #2. #3 seems wrong since you are not declaring it as const but instead it looks like a normal class property. I would personally prefer #2. It saves you the effort to create the companion and also allows you to use the constant in utility functions or extensions you might define in the same file. That said #1 or #2 is down to personal preference and should be decided on by the team, but it doesn’t really matter.
Related topics
Topic | Replies | Views | Activity | |
---|---|---|---|---|
How should one store constants in a Kotlin idiomatic style?
|
5 | 487 | October 19, 2024 | |
How do I define constants in an inner class? | 17 | 12955 | September 16, 2019 | |
Const vs val vs object vs top level | 10 | 9105 | September 26, 2018 | |
Logger declaration
|
5 | 2355 | January 2, 2017 | |
Constants Class | 12 | 29684 | November 27, 2017 |