SHOW:
|
|
- or go back to the newest paste.
| 1 | - | class AlbumDemo {
|
| 1 | + | class Person {
|
| 2 | - | // statically typed property |
| 2 | + | String firstName |
| 3 | - | String title |
| 3 | + | String lastName |
| 4 | - | |
| 4 | + | } |
| 5 | - | // dynamically typed property |
| 5 | + | |
| 6 | - | def price |
| 6 | + | def person1 = new Person(firstName: 'Eddard', lastName: 'Stark') |
| 7 | - | |
| 7 | + | assert "${person1.firstName} ${person1.lastName}" == "Eddard Stark"
|
| 8 | - | def printAlbum() {
|
| 8 | + | |
| 9 | - | println title + ': ' + price |
| 9 | + | def person2 = new Person() |
| 10 | - | } |
| 10 | + | person2.firstName = 'Tyrion' |
| 11 | - | |
| 11 | + | person2.setLastName 'Lannister' |
| 12 | - | static void main(String[] args) {
|
| 12 | + | assert "${person2.getFirstName()} ${person2.getLastName()}" == "Tyrion Lannister"
|
| 13 | - | def album = new AlbumDemo(title: 'Best Of 2010', price: 20.5) |
| 13 | + | |
| 14 | - | album.printAlbum() |
| 14 | + | |