当clear()方法调用抛出UnsupportedOperationException时如何清除地图的内容? [英] How to clear out the contents of a map when clear() method call throws UnsupportedOperationException?
问题描述
如果我在 clear()
方法调用时收到
UnsupportedOperationException
地图实例?
How can I empty a map contents if I keep getting an UnsupportedOperationException
when I call clear()
method on the map instance ?
推荐答案
你不应该。合作对象及其方法的合同中存在错误。您期望可修改的地图,但获得不可修改的视图。您应该重新定义合同和/或相应采用任何实现。如果你不控制一个,谁传递你的地图,那么可能有一个原因,它传递一个不可修改的视图。
You shouldn't. There is something wrong in the contracts of the collaborating objects and their methods. You expect a modifiable map, but get an unmodifiable view. You should redefine the contracts and/or adopt any of the implementations accordingly. If you are not in control of the one, who is passing you that map, then there is probably a reason for it passing you an unmodifiable view.
这篇关于当clear()方法调用抛出UnsupportedOperationException时如何清除地图的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!