5

Can anyone tell me why the following code fails to compile but the lambda version does:

Are there rules about the generic type inference? Anything I should avoid?

Failed:

EntityLayerManager.refreshLayerRenderables(
        wwd, this.networkNodeShapeLayer, nodeMap.values(),
        MissionDetailUIConst::createNetworkNodeRenderable,
        MissionDetailUIConst::updateNetworkNodeRenderable) // <<== FAILED 

Success (with normal lambda):

EntityLayerManager.refreshLayerRenderables(
        wwd, this.networkNodeShapeLayer, nodeMap.values(),
        MissionDetailUIConst::createNetworkNodeRenderable,
        (e, coll) -> MissionDetailUIConst.updateNetworkNodeRenderable(e, coll));

Success (with generic parameters specified):

EntityLayerManager.<EwmsVwNetworkNodeEntity, KolladaRoot>refreshLayerRenderables(
        wwd, this.networkNodeShapeLayer, nodeMap.values(),
        MissionDetailUIConst::createNetworkNodeRenderable,
        MissionDetailUIConst::updateNetworkNodeRenderable)

Referenced Methods:

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);
Tomasz Stanczak
  • 12,796
  • 1
  • 30
  • 32
jiping-s
  • 483
  • 1
  • 5
  • 13
  • 1
    Did you try with `BiPredicate>` in your `refreshLayerRenderables` ? – NoDataFound Aug 10 '14 at 07:56
  • Can you include the full error message? – Stuart Marks Aug 10 '14 at 13:47
  • BiPredicate> failed too. The full message is "The type MissionDetailUIConst does not define updateNetworkNodeRenderable(E, Collection) that is applicable here" – jiping-s Aug 10 '14 at 14:52
  • For questions like these it’s always recommended to include information about the compiler and its version used. Or, better, test with different compilers and include the results. – Holger Aug 11 '14 at 08:10
  • You should include the exact Generic type of `nodeMap`. Anyway, I tried to reproduce your setup as far as possible with all the missing types and the compiler accepted all three versions without errors (well, after inserting the missing semicolons). – Holger Aug 13 '14 at 10:07

1 Answers1

4

This is an Eclipse bug. I narrowed it down to the use of a nested generic parameter (Collection<R>) as the type of an argument (in BiPredicate) to the referenced method (specified as Collection<KolladaRoot>). It should compile fine in javac.exe.

I'd say stick with explicit type specification until it's fixed in 4.5 M2, it should have less effect (if any) than switching to lambdas.

Sean Van Gorder
  • 3,393
  • 26
  • 26