= and == difference in If statement Java

后端 未结 5 1254
感情败类
感情败类 2021-01-19 04:39

I am facing something strange here. Please help me understand if I am missing something. My if condition was supposed to be:

if(configuredPdf == true)
         


        
5条回答
  •  自闭症患者
    2021-01-19 05:12

    Yes, configuredPdf = true assigns true to your variable and returns true. Therefore if (configuredPdf = true) is a valid syntax even though it's usually a bug.

    It's safer to use if (configuredPdf) to avoid this kind of typo.

提交回复
热议问题