Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.Map; public class Main { @SuppressWarnings("unchecked") public static <K, V> V getOrDefault(Map<K, ?> map, K key, V defaultValue) { final Object v = map.get(key); if (v == null) return defaultValue; else return (V) v; } }