Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.6k views
in Technique[技术] by (71.8m points)

java - Why is my IDE telling me my if statement is redundant?

Why is NetBeans with TMC (IDE recommended by MOOC fi Java) telling my that my final if statement is redundant?

@Override
    public boolean equals(Object object) {
        if (this == object) {
            return true;
        }
        if (object == null) {
            return false;
        }
        if (this.getClass() != object.getClass()) {
            return false;
        }
        LicensePlate compared = (LicensePlate) object;
        
        if (!this.country.equals(compared.country)) {
            return false;
        }
        if (!this.liNumber.equals(compared.liNumber)) {
            return false;
        }
        return true;
        
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I would assume that you can simplify it using the return statement.

Example:

return this.liNumber.equals(compared.liNumber);


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...