Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

2.4. Expert Groovy

You should now be fairly confident in your ability to understand and write Groovy code. So far, most differences between Groovy and Java have fallen under the heading of “syntactic sugar.” We now move on to two important concepts that separate Groovy from Java on a more fundamental level: closures and Groovy’s dynamic nature.

2.4.1. Discovering closures

You’re probably familiar with the sort() method in java.util.Collections for sorting a list using a given comparator. This simple fragment of Java code will sort a list of strings, ignoring case, and print them to the console:


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint