Diamonds: cyclic inference error

Aleksey Shipilev aleksey.shipilev at
Mon Oct 15 09:15:07 PDT 2012

On 10/15/2012 06:50 PM, Maurizio Cimadamore wrote:
>> ...and if I write out the explicit type arguments within the diamond,
>> the test compiles well. Is this a spec-ed behavior, or just a bug?
> This is the spec'd behavior, yes. You are passing an implicit lambda to
> a method where the target type contains inference variables (because of
> diamond). Which means javac doesn't know what the lambda parameter types
> should be inferred to. Javac would try to delay type-checking of the
> lambda expression as much as possible (to see if other inference
> constraints can be derived from remaining argument expression) - but in
> this case there's no additional arguments. Either you specify the type
> of the diamond, or you specify the explicit lambda parameter type.

For the record, this one works:

        Map<String, Map<String, Counter>> map =
                new ComputeTreeMap<>(
                        (String s) -> new ComputeTreeMap<>(
                               (String x) -> new Counter()


More information about the lambda-dev mailing list