Are there any proposals for a way to avoid having ...
# language-proposals
a
Are there any proposals for a way to avoid having to specify params to be passed to parent classes constructor? for example if we have
Copy code
abstract class Foo(val id: String, val f1: String, val f2: String)
class Bar(id: String, f1: String, f2: String, val other: String): Foo(id, f1, f2)
I want to avoid having to specify the same props (
id
,
f1
,
f2
), and better yet would like to reuse the documentation across all the subclasses
n
I suggest doing
Copy code
abstract class Foo {
  abstract val id: String
  abstract val f1: String
  abstract val f2: String
}

class Bar(
  override val id: String,
  override val f1: String,
  override val f2: String,
) : Foo()
if you are in control of the abstract class
a
same issue of having to repeat
b
How about if the super class has a primary constructor, and the extending class/super class have their constructors omitted, it'll implicitly use the same constructor
abstract class Foo(a: A, b: B)
//class Bar(a: A, b: B) : Foo(a, b)
class Bar : Foo
I think Swift does something like this if a class has no constructors at all.
a
I think it still makes sense to explicitly state that there are params, I would just like having to repeat it for each subclass. In the example I gave there is only one child class Bar, but there can be many more. If I were to propose a solution, it would be something like being able to "type" or reference a group of params and use them like
class Bar(params foo ::Foo, val other: String): Foo(...foo)
where the
::Foo
is a method reference