glureau
05/11/2023, 8:17 AMJavier
05/11/2023, 8:25 AMglureau
05/11/2023, 9:18 AMKlitos Kyriacou
05/11/2023, 9:22 AMfun f(nullableField: Int?): String {
return nullableField?.let { "hello$it" } ?: "nobody"
}
fun g(nullableField: Int?): String {
val foobar = nullableField?.let { "hello$it" }
return foobar ?: "nobody"
}
Kotlin -> Bytecode -> Decompiled Java:
@NotNull
public static final String f(@Nullable Integer nullableField) {
String var10000;
if (nullableField != null) {
int it = ((Number)nullableField).intValue();
int var3 = false;
var10000 = "hello" + it;
if (var10000 != null) {
return var10000;
}
}
var10000 = "nobody";
return var10000;
}
@NotNull
public static final String g(@Nullable Integer nullableField) {
String var10000;
if (nullableField != null) {
int it = ((Number)nullableField).intValue();
int var4 = false;
var10000 = "hello" + it;
} else {
var10000 = null;
}
String foobar = var10000;
var10000 = foobar;
if (foobar == null) {
var10000 = "nobody";
}
return var10000;
}
glureau
05/11/2023, 9:31 AMif (var10000 != null)
makes no sense to me, as it's a local variable previously set with a non-null value.
And in the g() method, I'm not sure why we need var10000 = foobar;
glureau
05/11/2023, 9:32 AMKlitos Kyriacou
05/11/2023, 9:34 AMnullableField?.let { "hello$it" } ?: "nobody"
is that it produces code for the case when nullableField != null
but "hello$it" == null
. We know that can never happen, but JaCoCo doesn't.glureau
05/11/2023, 9:36 AMKlitos Kyriacou
05/11/2023, 10:00 AM