现在我正在研究责任链设计模式并使用Eclipse。
我正在尝试编译此代码,但出现编译错误“isLast 无法解析或不是字段”:
public class OverFive implements Discount {
private Discount next; //
public boolean isLast = false;
public void setNext(Discount next, boolean Last) {
this.next = next;
this.next.isLast = Last; // Here is the error.
}
public double DoDiscount(Budget budget) {
if (budget.getValue() > 500) {
return budget.getValue() * 0.10;
}
if (this.next.isLast == false) {
return next.DoDiscount(budget);
}
else {
return 0;
}
}
}
现在,这是界面:
public interface Discount {
double DoDiscount(Orcamento orcamento);
void setNext(Discount next, boolean Last);
}