クラス宣言で指定されたジェネリック パラメータを持つメソッドへのメソッド参照を作成しようとしています。ので、私は持っています:
public interface IExecutable<P extends IParameter> {
void execute(P parameter);
}
public class Parameter implements IParameter {
public void childSpecific() {
...
}
}
public class TestClass {
...
//somewhere in the code
public void foo(Parameter parameter) {
parameter.childSpecific();
}
public void test() {
IExecutable<?> executable = this::foo; //compilation error
// The type TestClass does not define inner(IParameter) that is applicable here
executable.execute(new Parameter()); //compilation error as well
// The method execute(capture#4-of ?) in the type IExecutable<capture#4-of ?> is not applicable for the arguments (Parameter)
}
...
}
ここで実行可能ファイルの具体的なジェネリック型がわからないことは明確です。使用する
IExecutable<Parameter> = ...
すぐに問題を解決しますが、その場合は不可能です。
明らかに、私は何か間違ったことをしています。しかし、それを機能させる方法は?
どうも。