https://kotlinlang.org logo
#announcements
Title
# announcements
n

nil2l

09/16/2017, 8:38 PM
Do you mean exception in constructor?
d

diesieben07

09/16/2017, 8:41 PM
No, I mean something like this:
Copy code
class Bar {

    val string: String

    constructor() {
        string = createString(this)
    }


}

fun createString(bar: Bar) = "abc"
You are leaking out an uninitialized reference to
Bar
in the constructor.
k

karelpeeters

09/16/2017, 8:43 PM
You can leak it right now to.
n

nil2l

09/16/2017, 8:44 PM
Cannot access '<this>' before superclass constructor has been called
d

diesieben07

09/16/2017, 8:45 PM
It was an argument against doing "a lot of stuff" in constructors.
n

nil2l

09/16/2017, 8:46 PM
I understood, just wrote exact Kotlin’s error. 🙂
d

diesieben07

09/16/2017, 8:47 PM
You get that if you try to use
this
inside the actual call to another constructor, yes.
My example actually compiles though 😉
n

nil2l

09/16/2017, 8:49 PM
Because your primary constructor has no params 🙂
2 Views