Let's say you have a lambda with a nullable `var` ...
# getting-started
j
Let's say you have a lambda with a nullable
var
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
?:
)
Copy code
var b: Int? = null
	listOf("a", "b", "c").forEach {
		if (b != null) {
			println(b as Int + 1)
		}
	}
VS
Copy code
var b: Int? = null
	listOf("a", "b", "c").forEach {
		if (b != null) {
			println(b!! + 1)
		}
	}