© Adam L. Davis 2016

Adam L. Davis, Learning Groovy, 10.1007/978-1-4842-2117-4_5

5. Coming from Java

Adam L. Davis

(1)New York, USA

Since most readers are already familiar with Java, it would be helpful to compare common Java idioms with the Groovy equivalent.

Default Method Values

One thing that might surprise you coming from Java is that in Groovy you can provide default values for method parameters. For example, let's say you have a fly method with a parameter called text:

1   def fly(String text = "flying") {println text}

This would essentially create two methods behind the scenes (from a Java standpoint):

1   def  fly() {println "flying"}2   def  fly(String text) {println text}

This can work with any number of parameters as long as the resulting ...

Get Learning Groovy 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.