Ant's
Ant's

Reputation: 13811

Groovy Closures Vs C# Anonymous Method, Are they similar?

I'm reading C#, and I came across the topic Anonymous method. As I know Groovy very well, I guess the Groovy Closures is very similar to C# Anonymous method. I checked the book's, online doc's the rules match. Like they wont execute until they have been invoked and so on.

Are these Groovy closures and C# Anonymous method are equal?

Or there are situation's where they behave differently?

Upvotes: 1

Views: 349

Answers (1)

Nathan
Nathan

Reputation: 10784

There may be circumstances where they will behave differently.

C# anonymous methods can be "modified closures" in that their are circumstances where the execution context can be modified after the closure is created. See Access to Modified Closure and ReSharper Warning - Access to Modified Closure for a more thorough explanation.

I believe that in Groovy, "closures" give more guarantees on the execution context being copied. However, it should be noted that my experience is in C#, and I have only limited exposure to Groovy.

Upvotes: 1

Related Questions