, use , , call-site, myVar .
IF myVar , MyType . :
var myVar: MyType = TODO()
autoClosable.use {
myVar.todo()
}
IF myVar lambda , - ObjectRef. ? , Java . myVar -. :
var myVar: MyType
autoClosable.use {
myVar = autoClosable.foo()
}
, println(myVar), , ObjectRef . .
IF - , , :
var myVar: MyType
try {
autoClosable.use {
myVar = it.foo()
}
} catch(e: Throwable) {
myVar = MyType()
}
println(myVar)
, myVar MyType, . :
var myVar: MyType
try {
TODO()
} catch(e: Throwable) {
myVar = MyType()
}
println(myVar)
Why didn't kotlin optimize its built-in functions for direct use MyTypefor recording?
The only thing I think the compiler does not know myVaris whether it will be used in the lambda body of another uninline function in the future. or kotlin want to maintain a semantic sequence for all functions.
source
share