I'm trying to create an interface with a bounded type parameter, with implementations supplying static nested classes to implement this parameter, as follows:
public interface InterfaceProblem<T extends IMyParameter>{
T getParameterInstance();
}
interface IMyParameter {}
class MyClass implements InterfaceProblem<MyParameter> {
public MyParameter getParameterInstance() {
return new MyParameter();
}
class MyParameter implements IMyParameter{}
}
This gives me a compile error "MyParameter cannot be resolved to a type" on the MyClass declaration and its method. This disappears if I move the static class to its own type:
class MyClass implements InterfaceProblem<MyParameter> {
public MyParameter getParameterInstance() {
return new MyParameter();
}
}
class MyParameter implements IMyParameter{}
However, I'd like to avoid that, since the MyParameter implementation is closely related to the MyClass implementation. Is there a better way I can acheive this? Is this correct compiler behaviour? (I'm using Eclipse Mars and Oracle jdk1.8.0_60)