The compiler complains because it thinks there is a path in which p
could be used in the System.out.println
without ever having been assigned to anything. It sees the if
statement, and decides that since p
is assigned only when the expression is true, but not when it's false, it's possible that p
might be unassigned after that.
Of course we look at this and figure the compiler has to be really dumb, because it's impossible for the expression to be false. Well ... in order to be consistent and not have behavior that varies from a compiler written by one vendor to a compiler written by another, the rules have to be specific about what the compiler is and isn't allowed to "figure out" about expressions. And apparently the rules don't let it figure out that Boolean.TRUE
is always true. However, I haven't memorized all the rules about definite assignment, so I don't know particularly what rules apply in this case.
More: The duplicate question mentioned in @Ravi Jiyani's comment does a good job of explaining the rules that I didn't know about.