```val loginPage = loginPageResponseBody.loginPage...
# announcements
s
Copy code
val 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) }
.
a
what’s the type of loginPage?
s
It's nullable and that's why I am doing the manual null check.
v
Probably
loginPage
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
.
s
With
?.let
it warns about it being an unnnecessary safe call.
v
With
loginPage
being nullable? o_O
s
I think unnecessary safe call thingy was coming because of the null check. Without null check I have to use
?.let
and with null check I can use
let
.
a
detail is important otherwise we can’t help you effectively. If you’re using anything else other than
loginPageResponseBody.loginPage
there would be no such issue
s
I am sorry if I have omitted any details that might be of use.
a
Ah, no, I guess it’s my question that’s wrong. I asked about the type, I know it’s of nullable type. What is loginPage? can you share a snippet, or at least the structure? Otherwise we are left to guess.
Hmm I also got a similar issue before but it was just an IDE issue, it was fine after I restarted.