Depends on case and constant name
# codingconventions
g
Depends on case and constant name
For example if constant is hard coupled to enclosing class I would use compantion object, like
Integer.MAX_VALUE
, if constant is just some constant value, something like
BUFFER_SIZE
, I rather use top level constant
also, sometimes you want to group constants to have better discoverability, like: View.GONE View.VISBLE So you can have VIEW_GONE and VIEW_VISIBLE, but companion object version looks better
f
Thanks for the explanation 👍
g
One more thing: For private constants I use top level declaration, no reason to use companion object for such case (the same syntax, additional unnecessary class)
f
Same here, actually i think that’s the primary use of top level declaration. Or if you wanna share same const for different classes in same file (which is again a rare use-case)