Enum hinzugefügt
parent
c00678f8f1
commit
abeb3da90b
|
@ -1,3 +1,41 @@
|
||||||
|
### Enums
|
||||||
|
Enums sind gleich wie in Java
|
||||||
|
|
||||||
|
```Groovy
|
||||||
|
enum Day{
|
||||||
|
MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY
|
||||||
|
}
|
||||||
|
|
||||||
|
Day today = Day.MONDAY
|
||||||
|
```
|
||||||
|
|
||||||
|
Man kann in Enums zusätzlich noch Eigenschaften und Methoden einbauen
|
||||||
|
|
||||||
|
```Groovy
|
||||||
|
enum Day{
|
||||||
|
MONDAY("First Day of the Week"),
|
||||||
|
TUESDAY("Second Day of the Week),
|
||||||
|
//...
|
||||||
|
|
||||||
|
final String description
|
||||||
|
|
||||||
|
Day(String description){
|
||||||
|
this.description = description
|
||||||
|
}
|
||||||
|
|
||||||
|
String getDescription(){
|
||||||
|
return description
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Day today = Day.FRIDAY
|
||||||
|
def description = today.getDescription
|
||||||
|
println("Today is $today: $description")
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Zusätzlich dazu kann man auch Methoden überschreiben (z.B. toString()-Methode)
|
||||||
|
|
||||||
### Ranges
|
### Ranges
|
||||||
Ähnlich wie in Ruby, jedoch nicht gleich
|
Ähnlich wie in Ruby, jedoch nicht gleich
|
||||||
```Groovy
|
```Groovy
|
||||||
|
@ -109,3 +147,5 @@ Entfernen eines Elements:
|
||||||
```Groovy
|
```Groovy
|
||||||
mySet.remove(1)
|
mySet.remove(1)
|
||||||
println mySet // [2,3,4,5,6,7]
|
println mySet // [2,3,4,5,6,7]
|
||||||
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue