= and == difference in If statement Java

后端 未结 5 1266
感情败类
感情败类 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:14

    What is happening is when the compiler comes to the if condition in your code, it assigns 'configuredpdf' to be true. Thus the condition

        if(configuredpdf = true)
    

    Becomes true and the loop executes successfully. However, the problem arises when we DON'T want this loop to be true. At that time when, for a given input, the compiler parses the if condition, it forcibly becomes true and executes the code written in if condition executes even if the data entered does not agreeing. That is why you will find that your code has a bug at the if condition.

提交回复
热议问题