Skip to content

Instantly share code, notes, and snippets.

@tobyweston
Created March 22, 2012 09:01
Show Gist options
  • Save tobyweston/2157239 to your computer and use it in GitHub Desktop.
Save tobyweston/2157239 to your computer and use it in GitHub Desktop.
mapping widget - a little bit of yuk
public static class ButtWipe {
public static <K, V> MapBuilder<K, V> map(K key, V value) {
return new MapBuilder<K, V>().map(key, value);
}
public static class MapBuilder<K, V> extends HashMap<K, V> {
private MapBuilder() {
}
public MapBuilder<K, V> map(K key, V value) {
put(key, value);
return this;
}
}
public void example() {
Map<String, Integer> example = map("hello", 1).map("world", 2).map("!", 3);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment