O'Reilly logo

Learning Groovy by Adam L. Davis

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

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

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