/** * Chapter 8: Classes * Section 8.4: Method Declarations * Author: Ken Barclay * * File: final.parameter.declaration.classes.8.4.groovy * * A class declaration may include any number of method declarations including * abstract method declarations. * * A method is given a name and an optional list of formal parameter declarations * enclosed in parentheses ( and ). A parameter declaration at its simplest is * simply a parameter name. It may be prefixed with a combination of optional * parameter modifiers (def or final), a type, or a type followed by the varargs * symbol (...). Two formal parameters with the same name is disallowed. * * A formal parameter may be optionally initialized with an expression, referred * to as a default parameter. If the number of actual parameters is fewer than * the number of formal parameters, then each actual is used to initialize, in * order, the non-default formal parameters. When all the actual parameters are * used in this manner, all subsequent formal parameters require default values. * * A formal parameter may be qualified as final. It is an error to assign a new * value to such an object. */ class Person { def dump(final x) { println "x (before): ${x}" x = 'Barclay' println "x (after): ${x}" } } def p = new Person() p.dump('Ken')