If I supply a valid local variable name, it seems to work fine:

private Map<SGID, Closure<SGMessage>> m1 = new LinkedHashMap<SGID,
Closure<SGMessage>> ()
private Map<SGID, Closure<SGMessage>> m2 = [:]

Cheers, Paul.

On Thu, Oct 30, 2025 at 2:52 AM Tommy Svensson <[email protected]> wrote:
>
> Hello Groovy users,
>
> Both of the following totally refuses to compile and I mega fail in 
> comprehending why!!!
>
>     private Map<SGID, Closure<SGMessage >> = new LinkedHashMap<SGID, 
> Closure<SGMessage >> ()
>     private Map<SGID, Closure<SGMessage >> = [:]
>
> Is it forbidden to put a Closure in a Map ? The Closure is a callback.
>
> I've used Closures before without problems. I totally fail to se the problem 
> here.
>
> I prefer the second variant with [:] to define a Map.
>
> I'm using Groovy 5.0.0
>
> What am I  doing wrong here ????
>
> Best Regards,
>
> Tommy Svensson
>
> [email protected]
>
>
>

Reply via email to