https://kotlinlang.org logo
Title
a

Andrew Gazelka

01/10/2019, 10:58 AM
is there any way to inherit super class default constructor values?
open class A(val a: String, val b: String = "hello")

class B(a: String, b: String, c: String) : A(a, b) {

}
in this scenario would it be possible to have
b
arg in class
B
have default value
"hello"
while being DRY?
k

karelpeeters

01/10/2019, 11:19 AM
There's no nice way to do that I'm afraid.
c

Czar

01/10/2019, 11:56 AM
companion object
comes to mind, but yeah, nothing elegant as in inheritance, you still have to specify them.
k

karelpeeters

01/10/2019, 12:05 PM
What would you do with a companion object?
a

Andrew Gazelka

01/10/2019, 12:25 PM
@karelpeeters store the default values and then reference them
c

Czar

01/10/2019, 1:13 PM
👆