Is there a way to get a reference a specific const...
# getting-started
v
Is there a way to get a reference a specific constructor? I.e. if I have
Copy code
class Foo(val Bar: String, val Fizz: String = "Buzz")
then when I do ::Foo, I’d get a reference to a 2 argument constructor (as it’s considered
primary
, as I understand), is there a way for me to get a reference to the constructor with 1 argument (besides e.g. getting all constructors and filtering them on that criteria)?
d
In your example there is only one constructor. If you have two, you can specify type of the resulting variable and you'll get the one you want:
Copy code
class A {
    constructor(x: String)

    constructor(): this("hello")
}

val c: () -> A = ::A // reference to no-arg constructor
👌 1
v
ah, so the version with default parameter filled in is not considered a separate constructor? I see. Thanks for the suggestion!
d
Yeah to get that one you'll have to use an explicit lambda.