Can I return early from the init block?
# getting-started
p
Can I return early from the init block?
r
not directly, but you can work around it like e.g. this:
Copy code
init {
    run {
        // do some stuff
        if (someCondition) {
            return@run
        }
    }
}
or:
Copy code
init {
    doInit()
}

private fun doInit() {
    // do some stuff
    if (someCondition) {
        return
    }
}
👍 1
➕ 1
s
isn't that just an if?
Copy code
init {
    // do some stuff
    if (someCondition) {
        // do more stuff
    }
}
p
Yes, but to reduce telescoping effects I prefer early exit