Advertisement
rplantiko

Injecting attributes from a map

Sep 2nd, 2011
561
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 0.37 KB | None | 0 0
  1. // Injecting attributes from a map
  2.  
  3. void set( map ) {
  4. // Does something with each of the values
  5.   for (entry in map) {
  6.     println "${entry.key} : ${entry.value}"
  7.     }
  8.   }
  9.  
  10. // Plain old Java  
  11. java.util.LinkedHashMap m = new java.util.LinkedHashMap();
  12. m.put("a","Alpha");
  13. m.put("b","Bravo");
  14. set(m);
  15.  
  16. // The same in Groovy
  17. set( a:"Alpha" ,
  18.      b:"Bravo" )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement