Hello - I have a situation where in I need to send a hashmap as an argument to another method. And I do not have any control over this other method and I have to make sure that the HashMap I am passing should not be updated.
I could have used Collections.unModifiableMap() to a get an unmodifiableMap but, the I need to specifically pass HashMap and not just any Map.
Why do you care that the immutable map is specifically a HashMap? Normally that kind of tight coupling is indicative of a design flaw.
And, if for whatever bizarre reason, you really really can't create a copy and really really do need a HashMap, since you already knew from reading the docs before you posted that unmodifiableMap() doesn't give you what you need, why are you opposed to spending 5 minutes extending HashMap? How can that possibly be "too much to do"? There can't be more than half a dozen methods to override, and the overrides will each be one single line--you can even make them identical, so you'd be able to just copy and paste for all but the first.