Difference between these two conditions?

前端 未结 6 2388
半阙折子戏
半阙折子戏 2020-12-11 08:45

Sorry if my question is silly or not it doesnot matter. But i just want to know what will happen in these two conditions.

public class Test {
    public stat         


        
6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-11 09:22

    The first if-statement test, whether str equals "test". The second if-statement test, whether "test" equals str. So the difference between these two if-statements is, that in the first you send a message to the str object with the argument "test". then the str object compares, whether it equals to the argument and return true or false. The second if-statement send a message to "test". "test" is also a string object. So now "test" compares, whether it equals to str and return true or false.

提交回复
热议问题