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 | |
---|---|---|---|---|
Const vs val vs object vs top level | 10 | 9191 | September 26, 2018 | |
Constants Class | 12 | 29820 | November 27, 2017 | |
How should one store constants in a Kotlin idiomatic style?
|
5 | 627 | October 19, 2024 | |
How do I define constants in an inner class? | 17 | 13056 | September 16, 2019 | |
Why does Kotlin need "const" keyword? | 14 | 37067 | July 12, 2018 |