Rob Elliot
08/15/2022, 8:58 AMinterface Something {
String getAConstant();
}
and you want the value of getAConstant
to be a constant, is there a less verbose way than this?
class ConcreteSomething : Something {
private val _constant = "constant value"
override fun getAConstant(): String = _constant
}
(It's not actually a String, it's calculated by calling other methods on a supertype using a constructor value, just simplifying things.)Klitos Kyriacou
08/15/2022, 9:21 AMoverride fun getAConstant() = "constant_value"
(It can thereafter be used as though it were a val, ConcreteSomething().aConstant
, but it has to be defined as a function because it's a Java interface.)Joffrey
08/15/2022, 9:24 AMSam
08/15/2022, 9:32 AMJoffrey
08/15/2022, 9:34 AMRob Elliot
08/15/2022, 9:51 AMJoffrey
08/15/2022, 9:54 AM