Re: Just can't figure out why these refuse to compile!
Paul King <[email protected]> Thu, 30 Oct 2025 06:43:41 +1000
| Newsgroups | gmane.comp.lang.groovy.user |
|---|---|
| Message-ID | <CAMbkE7Tq=o0-ndoBbJjzsGjt0R73-HEg_FpCQmObmucM_JoLEw@mail.gmail.com> |
If I supply a valid local variable name, it seems to work fine: private Map<SGID, Closure<SGMessage>> m1 =3D new LinkedHashMap<SGID, Closure<SGMessage>> () private Map<SGID, Closure<SGMessage>> m2 =3D [:] Cheers, Paul. On Thu, Oct 30, 2025 at 2:52=E2=80=AFAM Tommy Svensson <[email protected]> = wrote: > > Hello Groovy users, > > Both of the following totally refuses to compile and I mega fail in compr= ehending why!!! > > private Map<SGID, Closure<SGMessage >> =3D new LinkedHashMap<SGID, Cl= osure<SGMessage >> () > private Map<SGID, Closure<SGMessage >> =3D [:] > > 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 prob= lem 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] > > >