https://kotlinlang.org logo
#announcements
Title
# announcements
a

adams2

09/07/2017, 2:47 PM
where do you guys put constants? I've been putting them standalone at the bottom of the file, since it feels weird to have them above the class javadoc.
so like
Copy code
/**
 * Stuff
 */
class Foo {
    ...
}

internal const val PREFS_FILE = "somefile"
d

denis.shakinov

09/07/2017, 2:48 PM
you can use objects and put constants there
i mean companion objects
p

poohbar

09/07/2017, 2:51 PM
i put them above.. im used it it from ES6 javascript
s

stantronic

09/07/2017, 6:10 PM
I put them above also
a

arekolek

09/07/2017, 7:46 PM
I started putting them in companion object when I noticed that having anything outside activity class breaks some features of Android studio, for example the ability to run that activity
m

mmaillot

09/08/2017, 9:05 AM
Depends, if constant is used in one class, i'll use val prefsFile = "somefile" because val is immutable. If need in other class, I use an object to share it. but @adams2 solution seems very nice.
2 Views