Groovy: what’s the purpose of “def” in “def x = 0”?

In the following piece of code (taken from the Groovy Semantics Manual page), why prefix the assignment with the keyword def?

def x = 0
def y = 5

while ( y-- > 0 ) {
    println "" + x + " " + y
    x++
}

assert x == 5

The def keyword can be removed, and this snippet would produce the same results. So what’s the effect of the keyword def ?

6 Answers
6

Leave a Comment