public static < K , V > V getOrDefault ( final Map < K , V > map , final K key , final Function < K , V > supplier ) { V value = map . get ( key ) ; if ( value == null ) { value = supplier . apply ( key ) ; map . put ( key , value ) ; } return value ; }
A getOrDefault that doesn t create garbage if its suppler is non - capturing .