Map<String, Object> anymap = new ABMap(new HashMap());
anymap.put("a", 1);
anymap.put("b", "abc");
String b = anymap.getAny("b");
assert b == "abc";
int a = anymap.getAny("a");
assert a == 1;
Last active
December 17, 2015 12:09
-
-
Save kamikat/5607705 to your computer and use it in GitHub Desktop.
Java, "auto" class binding wrapper for Map class
This file contains hidden or 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
import java.utils.Map; | |
public class ABMap implements Map { | |
private final Map src; | |
public ABMap(Map src) { | |
this.src = src; | |
} | |
public T <T> getAny(Object key) { | |
Object value = src.get(key); | |
if(null != value) { | |
return (T) value; | |
}else{ | |
return null; | |
} | |
} | |
// Redirect all invoke to Map interface to `src` | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment