Skip to content

Instantly share code, notes, and snippets.

@smat
Created July 1, 2011 13:50
Show Gist options
  • Save smat/1058578 to your computer and use it in GitHub Desktop.
Save smat/1058578 to your computer and use it in GitHub Desktop.
Missing asMap-implementation (for Java)
public class Example {
public void example() {
Map<String, String> map = MapUtil.asMap("key", "value").entry("key2", "value2");
}
}
public class MapUtils {
public static <K, V> MapBuilder<K, V> asMap(K key, V value) {
return new MapBuilder<K, V>().entry(key, value);
}
public static class MapBuilder<K, V> extends HashMap<K, V> {
public MapBuilder<K, V> entry(K key, V value) {
this.put(key, value);
return this;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment