Perhaps it was bad practice but in Java I would often create something like:
public class MyService extends Service {
public static final String ACTION_CONNECTED = "blablabla";
...
}
And reference it in another class like:
MyService.ACTION_CONNECTED
This was great. I could keep my constants nicely associated with their class.
I can't seem to find an equivalent in Kotlin. I see solutions flying around suggesting people create constants files (objects) but I don't think that's very elegant. I want there to be some way to expose a top-level const val BLAB outside its file so I can keep my ClassName.CONSTANT syntax going but it doesn't look like it's in the cards.
Is there (and what is it) a Kotlin equilivant to the good old public static final with regard to sharing constants between classes?
class MyService {
companion object {
@JvmStatic const val ACTION_CONNECTED = "blablabla"
}
}
MyService.ACTION_CONNECTED
This will be the equivalent of public static final for kotlin
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With