Skip to content

What I Learned Today: Groovy Default Parameter Goodness

Default parameters can reference other parameters.

This little snippet of Groovy:

def f(x, y = x) {
  println "x=$x, y=$y"
}

f('hello', 'world')
f('hi')

Gives:

x=hello, y=world
x=hi, y=hi

Tags:

Java Enterprise Edition, JEE, JavaServer Pages, JSP, Tag Libraries, Servlets, Enterprise Java Beans, EJB, Java Messaging Service JMS, BEA Weblogic, JBoss, Application Servers, Spring Framework, Groovy, Grails, Griffon, Seam, Open Source, Service Oriented Architectures, SOA, Java 2 Standard Edition, J2SE