Question

Am looking for an efficient way to initialize a HashMap given that it's keys remain the same for any object created of the class it belongs to.

My current implementation initializes the HashMap everytime a new class object is created.

Thanks!

Was it helpful?

Solution

You can create a template Map, and use .clone() to generate new instances. You could also create a custom Map implementation that uses a copy-on-write policy to refer to a template "parent" Map.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top