Getting confused with == and = in “if” statement

前端 未结 5 478
时光说笑
时光说笑 2020-12-18 23:06

I know that we cant use assignment operator in if statements in java as we use in any other few languages.

that is

            int a;

            i         


        
5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-18 23:46

    In java, you don't have implicit casting. So non-boolean values or not automatically transformed to booleans.

    In the first case, the result of the statements is an int, which is non-boolean, which will not work. The last case, the result is boolean, which can be evaluated in an if-statement.

提交回复
热议问题