There's no way to inherit constructor parameters f...
# announcements
k
There's no way to inherit constructor parameters from a parent class, right? I'm looking for something like this:
Copy code
open class Parent(val a: Int, val b: Int)
class Child(val c: Int) : Parent(@inherit)
Child(a = 1, b = 2; c = 3)
d
it looks hard to code review
k
Maybe, but the context is that I have a bunch of classes that all need to extend the same parent and they all just pass trough the constructor values.
s
If your parent is an interface instead then you "only" have to write out the
override vals
, and can skip passing them
But I think that is the least verbose you can get
k
That's not too bad actually, I might go for that.
Even though it feels a bit cheaty simple smile
r
would be nice to have something similar to c++ 11 constructor inheritance
👍 2
s
Remember guys: Composition over inheritance 😉
k
Sometimes there really just is an "is a" relation between types, perfect for inheritance.