void (@NotNull K key, @NotNull V value) { Object current = myMap.get(key); if (current == null) { myMap.put(key, value); } else if (current instanceof ValueList) { //noinspection unchecked ((List<V>)current).add(value); } else { List<V> newList = new ValueList<>(); //noinspection unchecked newList.add((V)current); newList.add(value); myMap.put(key, newList); } }