Animesh Sahu
11/01/2020, 10:43 AMval delegatedProperty: Int by anotherObj::intProperty
using reflection? When val delegatedProperty: Int get() = anotherObj.intProperty
works out of the box (getter property without field).
Doesn't the former will have performance penalty due to reflections are involved (KProperty0
as seen by decompiler).gildor
11/01/2020, 2:10 PMAnimesh Sahu
11/01/2020, 2:14 PMval a: Int = 5
val b: Int by ::a
Here's the decompiled code of it:
final class TestKt$b$2 extends PropertyReference0Impl {
public static final KProperty0 INSTANCE = new TestKt$b$2();
TestKt$b$2() {
super(TestKt.class, "a", "getA()I", 1);
}
@Nullable
public Object get() {
return TestKt.getA();
}
}
public final class TestKt {
private static final int a = 5;
@NotNull
private static final KProperty0 b$delegate;
public static final int getA() {
return a;
}
public static final int getB() {
KProperty0 var0 = b$delegate;
Object var1 = null;
Object var2 = null;
boolean var3 = false;
return ((Number)var0.get()).intValue();
}
static {
b$delegate = TestKt$b$2.INSTANCE;
}
}
Animesh Sahu
11/01/2020, 2:14 PMAnimesh Sahu
11/01/2020, 2:16 PMgildor
11/01/2020, 2:22 PMAnimesh Sahu
11/01/2020, 2:24 PMgildor
11/01/2020, 2:25 PMDerek Peirce
11/01/2020, 6:27 PMgetB()
would be best off calling getA()
directly, with no KProperty
involved. In particular, I thought the 1.4 optimization was supposed to remove KProperty
usage where it isn't needed, such as with by lazy
.