我做错了什么,但不确定是什么. 试图制作一个查找 map ,为我提供我可以调用的函数.
问题的简单演示:
哦,我是.我是.
public class aa { /** doesn't matter for this example */}
♪Ab.Java♪
public class ab extends aa { /** doesn't matter for this example */}
Helper.java
public static short[] convert(ab foo)
{
//doesn't matter but eventually returns a short[] i.e.
return new short[5];
}
private interface aaConverterI
{
public <T extends aa> short[] method(Function<T, short[]> in);
}
private static Map<String, aaConverterI> bar = new HashMap<>();
static
{
bar.put("blah", Helper::convert);
}
编译器在Helper::Convert上说是The type Helper does not define convert(Function<T, short[]>) that is applicable here
,The method put(String, Helper.aaConverterI) in the type Map<String, aaConverterI> is not applicable for the arguments (String, Helper::convert)
.
如果我添加一个
static Function<ab, short[]> blahFunction = Helper::convert;
没有抱怨,我可以改变把
bar.put("blah", blahFunction);
这使得编译器只会在PUT上抱怨The method put(String, Helper.aaConverterI) in the type Map<String, Helper.aaConverterI> is not applicable for the arguments (String, Function<ab, short[]>)
.
我错过了一些东西,但我不确定是什么.try 添加@FunctionalInterface
来转换声明,但这并没有改变任何事情.
我遗漏了什么?谢谢!