Depends on the context. Are the constants only used within
FooX
? Are the constants directly related to the class? There’s no right answer, it ultimately depends on where you think the best placement for them is
serebit
05/29/2019, 4:22 AM
If the constants are only applicable to
FooX
, then I would put them in the companion object. If there are other functions/properties/classes in the file that use them, I would put them on the top-level
serebit
05/29/2019, 4:25 AM
Then companion object
serebit
05/29/2019, 5:52 AM
Personally, I wouldn’t worry too much about generated bytecode like this, especially when it comes down to a few lines
m
Mike
05/29/2019, 11:23 AM
And in kotlin code, the constants get inlined by the compiler regardless of how they're defined.