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 ...

Get Groovy in Action, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.