O'Reilly logo

Groovy in Action, Second Edition by Dierk König and Paul King with Guillaume Laforge, Hamlet D'Arcy, Cédric Champeau, Erik Pragt, and Jon Skeet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Appendix D. Cheat sheets

This appendix covers

  • Understanding GStrings
  • Using lists, closures, and regular expressions
  • Notating XML GPath

Cheat sheets provide you with quick information and examples to get you up and running quickly. For more details about any topic, refer to the corresponding section in the book or the Groovy documentation.

D.1. GStrings

For more information, see chapter 3.

// normal use def g1 = "1 + 1 equals ${1 + 1}" assert g1 == '1 + 1 equals 2' assert g1 instanceof CharSequence assert g1 instanceof GString def x = 10 def g2 = "$x" // reference assert g2 == "10" def g3 = "${x}" // expression assert g3 == "10" // lazy evaluation with a writeable closure! def g4 = "${ -> x}" // closure x = 20 // value change after definition ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required