Skip to content

Instantly share code, notes, and snippets.

@joeheyming
Created February 20, 2014 20:08
Show Gist options
  • Save joeheyming/9122145 to your computer and use it in GitHub Desktop.
Save joeheyming/9122145 to your computer and use it in GitHub Desktop.
java getNamedArgs
public class Utils {
public static Map<String,Object> getNamedArgs(Object... args) {
Map<String,Object> obj = new HashMap<String,Object>();
for (int i = 0, i < args.length; i += 2) {
obj.put((String)args[i], args[i+1]);
}
return obj;
}
}
//...
// then you can take any variable argument function and slap this on:
public void doSomething(Object... args) {
HashMap<String,Object> namedArgs = Utils.getNamedArgs(args);
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment