Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 506
Shawn Beachy Avatar asked Oct 25 '17 19:10

Shawn Beachy


1 Answers

Probably there’s a compilation problem. The screenshot shows an impossible scenario. Where do you start the app? Try to rebuild and then debug again. Also try to add some logs.

It’s not due to the way you chose to check the Boolean expression...

like image 142
s1m0nw1 Avatar answered Sep 20 '22 07:09

s1m0nw1