AbAppletic AbAppletic - 4 months ago 11
Android Question

Why isn't the compiler noticing that a boolean has been declared true?

Take a look at my code below:

private void implementVisibility(EditText A, EditText B, ImageButton C, boolean visible) {
if (visible) {
A.setVisibility(View.VISIBLE);
B.setVisibility(View.VISIBLE);
C.setVisibility(View.VISIBLE);
}
else if(!visible){

}

}


At the line
else if(!visible)
I get the warning: "
Condition !visible is always true
" and "
Value visible is always false
". But if you take a look at my previous method:

if (count2.getVisibility() == View.INVISIBLE) {
implementVisibility(count2, action2, remove2,true);
}


"
visible
" is
true
, therefor, it isn't always false. Why isn't the compiler noticing that it isn't ALWAYS false?

Note: Please don't downvote just because this question is heavily downvoted. This question has been edited and improved. Thank you.

Answer

By the time program control gets to else if(!visible){, visible can only be false.

Your compiler is hinting that you should clarify your code to else { instead.