groovy-lecture/assignments/solutions/safe-navigation2.groovy

15 lines
395 B
Groovy
Raw Normal View History

2024-06-09 20:55:46 +02:00
class Person {
def name
def alter
def printIfAdult() {
if (this.alter > 17) {
println this.name + " ist volljährig."
}
}
}
def personen = [new Person(name: "Max", alter: 12), new Person(name: "Karl", alter: 40), new Person(name: "Laura", alter: 23), new Person(name: "Ali", alter: 15)]
// Hier den Spread-Operator benutzen
personen*.printIfAdult()