1
我有我的分數程序運行平穩,但在NetBeans IDE告訴我下面的if
是多餘的:冗餘如果消息
public boolean equals(Object other)
{
Fraction bool = (Fraction) other;
if(this.numerator == bool.numerator && this.denominator == bool.denominator)
{
return true;
}
else return false;
}
上面的代碼編譯/完美運行,並且通過了所有的測試案例,但多餘的標誌通過NetBeans真的困擾着我。我將reduceToLowestTerms()
添加到我的代碼中,並且該標誌消失,但我的構造函數中已有reduceToLowestTerms()
。這是(根據於NetBeans)非冗餘的代碼如下所示:
public boolean equals(Object other)
{
Fraction bool = (Fraction) other;
if(this.numerator == bool.numerator && this.denominator == bool.denominator)
{
bool.reduceToLowestTerms();
this.reduceToLowestTerms();
return true;
}
else return false;
}
任何建議,將不勝感激
你確定這是說'如果'是多餘的,而不是'else'? – DaveH 2015-03-02 23:06:46
'reduceToLowestTerms()'做了什麼?我能找到的唯一'Fraction'類是在apache common-lang中,它沒有這個方法,所以我假設這是你寫的一些自定義分數類? – azurefrog 2015-03-02 23:08:01
你可以發佈分數類嗎? – libik 2015-03-02 23:09:17