Tuesday 11 September 2012

scramble


MAP :

"harish" "viv" ]
public function({
println x.1;
}
function()


brings error 




whereas

id "harish" "viv" ]
public function({
println x.id;
}
function()

works fine giving output  harish

To solve the first problem we faced when we had integer as key
is


"harish" "viv" ]
public function({
println x.get(1);
}
function()

works fine giving output : harish


________________________________________________________________________________

Similarly
id "harish" "viv" ]
public function({
println x.get(id);
}
function()

flings error 






But
id "harish" "viv" ]
public function({
println x.get("id");
}
function()

works fine giving output as harish








































































































































































"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