mercredi 25 octobre 2017

Kotlin if statement executing even when false

I'm trying to check if a profile has an image URL set and, if so, load it into an ImageView:

val hasImage = image != null && image.isNotBlank()

if (hasImage) {
    Picasso.with(context).load(image).into(row.image)
}

image is a nullable string. The problem is that even when hasImage is false, it still loads the image, as you can see:

WHYYYYY

However, if I do val hasImage = false it behaves as expected.

I'm incredibly confused as to what is going on here. Why is the if condition still executing?

Aucun commentaire:

Enregistrer un commentaire