I used this code to see what it prints out:
System.out.println("The value of profileUserInfo.cityUserProfile is: "+profileUserInfo.cityUserProfile);
System.out.println("The value of profileUserInfo.cityUserProfile.equals(null) is: "+profileUserInfo.cityUserProfile.equals(null));
It prints out this:
The value of profileUserInfo.cityUserProfile is: null
The value of profileUserInfo.cityUserProfile.equals(null) is: false
I am trying to understand the above. profileUserInfo is an object of course. Basically this is an Android app and I want to do one thing or another depending on the value of profileUserInfo.cityUserProfile. If it is NULL, I want to do one thing. If it is NOT NULL, I want to do another thing. But when I run the following if statement, it always goes to the else block:
if (profileInfo.cityProfile.equals(null)) {
....
}else{
....
}
It makes sense that the code always reads the block in the else section because profileUserInfo.cityUserProfile.equals(null) always returns false. But I do not understand why it returns false all the time, even when profileUserInfo.cityUserProfile is clearly null. Even when I print out profileUserInfo.cityUserProfile by using System.out.println("The value of profileUserInfo.cityUserProfile is: "+profileUserInfo.cityUserProfile);, I can confirm it is definitely null. Maybe because profileUserInfo is an object and even though profileUserInfo.cityUserProfile is null, but other elements such as profileUserInfo.subscriptionUserProfile are not null? Maybe everything in the profileUserInfo object must be null for profileUserInfo.cityUserProfile to return null, even when profileUserInfo.cityUserProfile is definitely null? I hope I did not make my question too long and confusing. Thank you for your help.
Aucun commentaire:
Enregistrer un commentaire