Replace this if-then-else statement by a single return statement

前端 未结 6 1299
天命终不由人
天命终不由人 2020-12-21 01:13

While solving sonarQube issue i face the below warning,does any one tell me how to overcome this warning

Method:-

@Override
    public boolean equals         


        
6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-21 01:29

    Not completely sure of your intent for the if-statements that return false but it seems as if you could simply always return false unless "this == obj".

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        else
            return false;
    }
    

    This same thing could be accomplished with one line

    @Override
    public boolean equals(Object obj) {
        return this == obj;
    }
    

提交回复
热议问题