我想在JUnit测试用例中创建一个对象KalkulatorI.AccumulatorI
。当我创建Kalkulator.Accumulator
时,它就可以了(Kalkulator.Accumulator t2 = new Kalkulator().new Accumulator()
)。如何创建这样的接口对象?我试过了:
KalkulatorI.AccumulatorI t = new KalkulatorI.AccumulatorI();
或
KalkulatorI.AccumulatorI t = new KalkulatorI().new AccumulatorI();
但它不起作用。
AccumulatorI.java
:
public interface AccumulatorI {
public int getValue();
public void setValue(int acc);
}
KalkulatorI.java
:
public interface KalkulatorI {
public void setAccumulatorA(AccumulatorI a);
public void setAccumulatorB(AccumulatorI a);
}
Kalkulator.java
:
public class Kalkulator implements KalkulatorI {
private AccumulatorI AA;
private AccumulatorI BB;
class Accumulator implements AccumulatorI{
private int acc;
public int getValue(){
int res = this.acc;
return res;
}
public void setValue(int acc){
this.acc=acc;
}
}
public void setAccumulatorA(AccumulatorI a){
this.AA=a;
}
public void setAccumulatorB(AccumulatorI a){
this.BB=a;
}
}