Skip to content

Instantly share code, notes, and snippets.

@rz7d
Created September 26, 2016 12:22
Show Gist options
  • Save rz7d/56a6b2a2b7e62d83e2425e8e30d5b128 to your computer and use it in GitHub Desktop.
Save rz7d/56a6b2a2b7e62d83e2425e8e30d5b128 to your computer and use it in GitHub Desktop.
/**
* @param map Map to cast
* @return cast map
*/
@SuppressWarnings("unchecked")
public static <K, V> Map<K, V> castMap(Map<?, ?> map) {
Map<K, V> result = new HashMap<K, V>();
for ( Entry<?, ?> entry : map.entrySet() ) {
result.put((K) entry.getKey(), (V) entry.getValue());
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment