Initialize static map in Java interface
Updated at June 29, 2019
Sometimes, we need define a map constant in interface, but as interface can’t define initializer or static initializer block, how are we going to put values into the map and initialize it?
One way is to define an anonymous class that inherits from Hashmap, and initialize the map in the initialize block in the new anonymous class.