janvladimirmostert
09/27/2017, 10:44 AMvar
declared outside the lambda and you want to make use of that var inside the lambda
you are 100% certain that your var is not null and that another thread won't change it, which is the better style to use to stop the compiler from complaining?
(Int is just for the example, assume it's a session object or something else where we can't assume a default value using ?:
)
var b: Int? = null
listOf("a", "b", "c").forEach {
if (b != null) {
println(b as Int + 1)
}
}
VS
var b: Int? = null
listOf("a", "b", "c").forEach {
if (b != null) {
println(b!! + 1)
}
}