This content has been marked as final. Show 8 replies
sorry - could you explain a bit more?
That creates a new HashMap with the same contents. The callee can do what he likes to it without affixing the original.
Did you consider reading the Javadoc?
Hi - thanks! and yes I have read the docs :), your one line just did not make sense to me as I was actually looking something where I dont need to create a copy and preserve the original.
Something similar to Collections.unModifiableMap().
I could even try extending HashMap, but thats too much to do...
Anyway Thanks again!
Why don't you want to create a copy?
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.
Crossposting without indicating you have done so is rude. Please do not do it again.
Exactly. Change the target method to accept a Map. It has no business requiring a HashMap.
I am very sorry about this. And definitely this would not occur again.