This questions is NOT about style, for if it was I would settle for using 'each' all the time. Np, this time I'm coming from a different angle. I am investigating backwards compatibility of Gradle plugins written in Groovy.

With Gradle 2.8, the embedded version of Groovy is 2.4.4, whereas with earlier 2.x versions it is a Groovy 2.3.x version. This leads to an 'interesting' situation where one might compile a Gradle plugin using Gradle 2.13 and then try to run it with say Gradle 2.1. Let's start with an example first.

Normally one might do the following:

   void method(Set<String> collection)  {

       collection.each { println it }

   }

However if that is compiled with Groovy 2.4.x and then run with Groovy 2.3.x it will fail with NoSuchMethodError. This is usually due to GROOVY-6863. Most people will never see this as they will not usually go backwards. However in the Gradle situation this is real concern. So far in all cases that I have seen I can work around the problem by writing

   void method(Set<String> collection)  {

       for( String it in collection)  { println it }

   }

This brings me to the question, whether there is any performance problem here or is this a fine solution?

--
Schalk W. Cronjé
Twitter / Ello / Toeter : @ysb33r

Reply via email to