June 2018
Intermediate to advanced
316 pages
6h 34m
English
If you want to do something that doesn't fit the backing fields scheme (as in the case described earlier), you can use backing properties. Let's rewrite the Button class to use backing properties:
class Button { private var _text: String? = null var text: String set(value) { println(value) _text = value } get() { return _text + _text } var backgroundColor: Int? = null var onClickListener: ((Button) -> Unit)? = null fun printText() { println(_text) }}
Here it is decompiled to Java code:
public final class Button { private String _text; @Nullable private Integer backgroundColor; @Nullable private Function1 onClickListener; @NotNull public final String getText() { return Intrinsics.stringPlus(this._text, this._text); } public ...
Read now
Unlock full access