Why does if(Boolean.TRUE) {…} and if(true) {…} work differently in Java

前端 未结 3 728
小蘑菇
小蘑菇 2020-12-19 00:08

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

3条回答
  •  温柔的废话
    2020-12-19 00:53

    It does throw this error because it does not know what hides behind Boolean.TRUE. TRUE is a static field of the type boolean in the class Boolean, but its value could also be false. It isn't obviously, 'though.

提交回复
热议问题