I want to know the difference between Boolean.TRUE
and true
values inside an if
clause. Why does it give me a compilation error (that a value may not have been initialized) when I use Boolean.TRUE
instead of true
.
Below is my code :
public class Test {
public void method1() {
int x;
if(Boolean.TRUE) {
x = 200;
}
System.out.println("x: " + x); // Compilation error
}
public void method2() {
int x;
if(true) {
x = 200;
}
System.out.println("x: " + x); // Compiles fine
}
}