def actually defines the scope of the variable being defined
x = 4
public function() {
println x;
}
function()
o/p -> 4
whereas
def x = 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