Pre-Initializing a HashMap with Initializers #airhacks #java #short

preview_player
Показать описание
Java iInitializers can be used to create an immutable HashMap with initial data.

Рекомендации по теме
Комментарии
Автор

It's antypattern. When you initialize hashmap like that after each usage it will create anonymous extra class, in general it first step to memory leak issues.

mareksiwiec
Автор

An other way,
new HashMap<>(Map.of(
"hello", "duke",
"world", "java"));

lilvulgate
welcome to shbcf.ru