When the `photo` property is null, hasPhoto() seem...
# announcements
n
When the
photo
property is null, hasPhoto() seems to return true and control goes to the next statement (Kotlin 1.2.60)
c
if you assign
null
to
photo
it becomes initialized, so this is correct. Although I wonder, how did you assign null to non-nullable property? Reflection?
n
Well, the property is not nullable, but my API sends a null value. So Gson apparently assigns null to the property and things go bad.
d
Is it necessary to use lateinit in this example?
n
I did it to avoid using ?. or !!, but I think I will remove it.
d
Optional value contain native analog “has…” )
I think, best way is using clean optional value in this example
👍 1
i
Does it work if you remove
open
modifier?
t
If you've got an external API setting it to null anyway, using lateinit to avoid ?. just opens you up to problems because you've bypassed the null safety kotlin gives you
3
n
@Tony Hoyle Yes, I’ve changed it to nullable.
lateinit
was a really bad idea in this case. I hadn’t thought that gson could set it to null anyway.