Consider this example:
public interface TestInterface {
ParamInterface get();
void set(ParamInterface param);
public interface ParamInterface {
}
}
I want implement both interfaces, like this:
public class Test implements TestInterface {
private Param param;
@Override
public Param get() {
return param;
}
@Override
public void set(Param param) {
this.param = param;
}
public class Param implements ParamInterface {
//
}
}
Why getter is valid, but in setter has error?
Error: The method
set(Test.Param)of type Test mustoverrideor implement a supertype method
EDIT: I undestand the problem, but I want restrict argument type to Param type. I can solve this example using generics, but if I have more mehtods in same situation, it is not a good solution.
public interface ITest<T extends ITest.IParam> {
T get();
void set(T param);
public interface IParam {
}
}
public class Test implements ITest<Test.Param> {
private Param param;
@Override
public Param get() {
return param;
}
@Override
public void set(Param param) {
this.param = param;
}
public class Param implements ITest.IParam {
}
}