This assumes that you have setup groovy as per Setting up Groovy and groovysh beginner for eval exp, dynamic typing, operator overloading & closure.
Step 1: Start the groovyConsole from a command prompt
|
1 |
c:\TOOLS\groovy-2.4.3\bin>groovyConsole |
Step 2: Run the following Groovy Plain Old Object code
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
package com.plain.old.groovy.object public class Person{ String firstName String lastName int age def address static void main(def args) { Person p = new Person() // use the generated access methods p.setFirstName("John") // also uses the generated access method p.lastName = "Smith" p.address = ("Alice Street"); println(p.firstName + " " + p.lastName); // use the generated constructor p = new Person(firstName: "Samuel", lastName:"Pearce"); println(p.firstName + " " + p.lastName); } } |
Execute it as a Groovy script.
…