I try to run the following code, but the code can't pass compile, I get the error:
Smart cast to 'Long' is impossible, because 'i' is a mutable property that could have been changed by this time
Why?
class MyClass1(var i: Long?) {
fun change(): Long? {
if (i != null) {
return i + 10L
} else {
return 5L
}
}
}
I wrote the code MyClass2 in Java, it can work well, why?
class MyClass2{
private Long i;
public MyClass2(Long k){
i=k;
}
public Long change(){
if (i!=null){
return i+10L;
}else {
return 5L;
}
}
}