Tuesday 11 September 2012

"def" keyword in groovy


def actually defines the scope of the variable being defined


4
public function({
println x;
}
function()


o/p -> 4

whereas 

def 4
public function({
println x;
}
function()


o/p -> 




so the the declaration without def makes it global .
But people say that it is good to use variable declarations with def 
so that , it does not unnecessarily interfere with the variables 
inside functions 

I got a rough idea from





















































































No comments:

Post a Comment