谁能告诉我为什么以下代码无法编译但 lambda 版本可以:
有关于泛型类型推断的规则吗?我应该避免什么?
失败的:
EntityLayerManager.refreshLayerRenderables(
wwd, this.networkNodeShapeLayer, nodeMap.values(),
MissionDetailUIConst::createNetworkNodeRenderable,
MissionDetailUIConst::updateNetworkNodeRenderable) // <<== FAILED
成功(使用正常的 lambda):
EntityLayerManager.refreshLayerRenderables(
wwd, this.networkNodeShapeLayer, nodeMap.values(),
MissionDetailUIConst::createNetworkNodeRenderable,
(e, coll) -> MissionDetailUIConst.updateNetworkNodeRenderable(e, coll));
成功(指定通用参数):
EntityLayerManager.<EwmsVwNetworkNodeEntity, KolladaRoot>refreshLayerRenderables(
wwd, this.networkNodeShapeLayer, nodeMap.values(),
MissionDetailUIConst::createNetworkNodeRenderable,
MissionDetailUIConst::updateNetworkNodeRenderable)
参考方法:
public static <E, R extends Renderable> int refreshLayerRenderables(WorldWindow wwd,
RenderableLayer renderableLayer, Collection<E> entityList,
Function<E, ? extends Collection<? extends R>> createRenderables,
BiPredicate<E, Collection<R>> updateRenderables);
public static Collection<KolladaRoot> createNetworkNodeRenderable(EwmsVwNetworkNodeEntity networkNode);
public static boolean updateNetworkNodeRenderable(EwmsVwNetworkNodeEntity networkNode, Collection<KolladaRoot> colladaRootCollection);