/** * Factory method to create an unmodifiable map. * * @param <K> the key type * @param <V> the value type * @param map the map to decorate, must not be null * @return a new unmodifiable map * @throws NullPointerException if map is null * @since 4.0 */ public static <K, V> Map<K, V> unmodifiableMap(final Map<? extends K, ? extends V> map) { if (map instanceof Unmodifiable) { @SuppressWarnings("unchecked") // safe to upcast final Map<K, V> tmpMap = (Map<K, V>) map; return tmpMap; } return new UnmodifiableMap<>(map); }