Equality comparison of `boolean` and `Object` allowed?

前端 未结 2 1725
花落未央
花落未央 2021-01-04 17:47

The following code

public class TestComparison {
    public static void main(String[] args) throws Exception {
        boolean b = true;
        Object o = n         


        
2条回答
  •  感情败类
    2021-01-04 18:19

    It's your project language level setting. You are probably using a Java 7 compiler with Java 6 semantics. I don't have Eclipse here, but I reproduced it in IntelliJ, which gave errors when the language level was on Java 6, even though the compiler I used was 7. I guess Eclipse has the same. This link explains it.

提交回复
热议问题