tateisu
01/31/2018, 11:10 AM// I have to copy to local variable
fun menberFunction(){
var x = this.x
if( x == null ){
x = X()
this.x=x
}
codeUsingX(x)
// this.x may reset to null outside of this function.
}
// I want just using this.x
fun menberFunction(){
if( x == null ) x = X()
codeUsingX(x)
// this.x may reset to null outside of this function.
}
Andreas Sinz
01/31/2018, 11:16 AMval x = this.x ?: X()
X
tateisu
01/31/2018, 11:17 AMthis.x=x
Andreas Sinz
01/31/2018, 11:18 AMtateisu
01/31/2018, 11:20 AMAndreas Sinz
01/31/2018, 11:22 AMnull
and afterwards use it like a non-nullable var?tateisu
01/31/2018, 11:26 AMAndreas Sinz
01/31/2018, 11:37 AMthis.x
isn't manipulated during the execution of the functionsthis.x
nullable?tateisu
01/31/2018, 11:38 AMAndreas Sinz
01/31/2018, 11:44 AMnull
and X()
tateisu
01/31/2018, 11:55 AMAndreas Sinz
01/31/2018, 1:40 PMtateisu
02/01/2018, 6:12 AMAndreas Sinz
02/01/2018, 7:51 AM