我正在尝试创建方法引用的哈希映射 我可以通过声明我的自定义界面来做到这一点,例如
private interface UICustom {
View create(MyObject element);
}
我可以将我的方法添加到hashmap中:
hashmap.put("value", this::addField);
我在想是否可以避免宣布我的自定义界面,也许我已经可以使用已经可以使用的东西了
所以我找到了java.util.function.Function
,但是当我尝试function.apply
时,我收到了警告,即所需的最小SDK为24但我不能使用它。
有没有办法使用一些已经存在的功能界面而不声明我自己的?
答案 0 :(得分:0)
FunctionalInterface are available from JDK 8. And it seems like JDK 8 can be used with SDK 24 onwards.
::
operator is a method reference, and it is an example of Functional Interface type.