gregschlom
07/01/2016, 5:22 PMpublic final class Foo {
private int a = 2;
public final int getA() {
return this.a;
}
public final void setA(int value) {
Log.i("##", "setter called with: " + value);
this.a = value;
}
}
Snippet 3 and 4 give this:
public final class Foo {
private int a;
public final int getA() {
return this.a;
}
public final void setA(int value) {
Log.i("##", "setter called with: " + value);
this.a = value;
}
public Foo() {
this.setA(2);
}
}
`
- So ok, I understand Snippet 1: the backing field is initialized directly, bypassing the setter. This is a little bit counter-intuitive and should probably be documented on https://kotlinlang.org/docs/reference/properties.html
- The generated code for snippet 3 and snippet 4 is identical, and I see no reason why snippet 2 would not compile. Therefore I think this should be categorized as a compiler bug.