I want to create an object KalkulatorI.AccumulatorI
in a JUnit test case. When I create Kalkulator.Accumulator
it's ok ( Kalkulator.Accumulator t2 = new Kalkulator().new Accumulator()
). How can I create such a interface object? I tried:
KalkulatorI.AccumulatorI t = new KalkulatorI.AccumulatorI();
or
KalkulatorI.AccumulatorI t = new KalkulatorI().new AccumulatorI();
but it doesn't work.
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;
}
}
You cannot instantiate interface so there is no way to call new AccumulatorI()
. Please look at the Oracle's documentation
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.