I have class, which in primary constructor has some fields:
class SomeData(val counter: Int...) { // some logic}
I need to create a constant. I usually do it like this:
companion object {
private const val MAX_VALUE = 1000
}
But in my case, to declare a constant, I need to use a field from the class SomeData
. But to access the field counter
from SomeData
class I need to create an instance of this class and then access the field.
Is it normal practice to do something like this?
Or is it better to declare this constant inside the class:
private val MAX_VALUE = counter/ 2
But in that case, Android Studio warns me:
Private property name 'MAX_VALUE ' should not contain underscores in the middle or the end
How should I declare a constant?