KronicDeth
12/18/2017, 3:30 PMprivate set
and custom get
?
java
private ProjctSdksModel myModel
public ProjectSdksModel getModel() {
if (myModel == null) {
myModel = new ProjectSdksModel();
myModel.reset(null);
}
return myModel;
If I try
kotlin
var model: ProjectSdksModel? = null
get() {
if (this.model == null) {
}
return this.model
}
private set
I get warning that this.model
is or model
is recursive and my google-fu is failing for how to refer to the current property inside the getterRuckus
12/18/2017, 3:35 PMthis.model
with field
https://kotlinlang.org/docs/reference/properties.html#backing-fieldsKronicDeth
12/18/2017, 3:35 PM!!
immediately after initializing the field
? I assume the mutability warning is for concurrency
get() {
if (field == null) {
field = ProjectSdksModel()
field!!.reset(null)
}
return field
}
Ruckus
12/18/2017, 3:39 PMfield = ProjectSdksModel().apply { reset(null) }
KronicDeth
12/18/2017, 3:41 PMnull
reset back to field
. It's not just a lateinit - there's other code that can reset the field to null
Ruckus
12/18/2017, 3:43 PMreset(null)
does, but a backing property should help separate the logic more cleanly.umar
12/18/2017, 4:32 PM