Created
July 1, 2011 13:50
-
-
Save smat/1058578 to your computer and use it in GitHub Desktop.
Missing asMap-implementation (for Java)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Example { | |
public void example() { | |
Map<String, String> map = MapUtil.asMap("key", "value").entry("key2", "value2"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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