Sudhir Singh Khanger
02/12/2021, 8:05 AMval loginPage = loginPageResponseBody.loginPage
if (loginPage != null) {
loginPageData.postValue(loginPage)
}
If I am doing the null check then why does postValue
method complains about requiring Expected non-nullable value
. I don't get this error with loginPage.let { loginPageData.postValue(it) }
.allan.conda
02/12/2021, 8:10 AMSudhir Singh Khanger
02/12/2021, 8:40 AMVampire
02/12/2021, 8:56 AMloginPage
has a custom getter, so the returned value can change anytime and it cannot be smart-casted to non-null. With the let
the custom getter is not called again, but it should probably be ?.let
.Sudhir Singh Khanger
02/12/2021, 8:59 AM?.let
it warns about it being an unnnecessary safe call.Vampire
02/12/2021, 9:01 AMloginPage
being nullable? o_OSudhir Singh Khanger
02/12/2021, 10:29 AM?.let
and with null check I can use let
.allan.conda
02/12/2021, 10:37 AMloginPageResponseBody.loginPage
there would be no such issueSudhir Singh Khanger
02/12/2021, 10:43 AMallan.conda
02/12/2021, 10:47 AMallan.conda
02/12/2021, 10:48 AM