How to use this boolean in an if statement?

前端 未结 8 1568
一个人的身影
一个人的身影 2020-11-28 15:35
private String getWhoozitYs(){
    StringBuffer sb = new StringBuffer();
    boolean stop = generator.nextBoolean();
    if(stop = true)
    {
        sb.append(\"y\         


        
8条回答
  •  自闭症患者
    2020-11-28 16:37

    if(stop == true)
    

    or

    if(stop)
    

    = is for assignment.

    == is for checking condition.

    if(stop = true) 
    

    It will assign true to stop and evaluates if(true). So it will always execute the code inside if because stop will always being assigned with true.

提交回复
热议问题