欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

95-30-025-java.util-AbstractMap

程序员文章站 2022-03-15 13:11:24
...

1.世界

95-30-025-java.util-AbstractMap

1.类图

95-30-025-java.util-AbstractMap

2.源码解析

This class provides a skeletal implementation of the <tt>Map</tt>
interface, to minimize the effort required to implement this interface.

该类提供Map接口的基本实现,以最小化实现此接口所需的工作。

<p>To implement an unmodifiable map, the programmer needs only to extend this
class and provide an implementation for the <tt>entrySet</tt> method, which
returns a set-view of the map's mappings.  Typically, the returned set
will, in turn, be implemented atop <tt>AbstractSet</tt>.  This set should
not support the <tt>add</tt> or <tt>remove</tt> methods, and its iterator
should not support the <tt>remove</tt> method.

​ 要实现不可修改的映射,程序员只需要扩展这个类并为entrySet方法提供一个实现,该方法返回映射的集视图。通常,返回的集合将依次在AbstractSet之上实现。这个集合不应该支持add或remove方法,它的迭代器也不应该支持remove方法。

<p>To implement a modifiable map, the programmer must additionally override
this class's <tt>put</tt> method (which otherwise throws an
<tt>UnsupportedOperationException</tt>), and the iterator returned by
<tt>entrySet().iterator()</tt> must additionally implement its
<tt>remove</tt> method.

​ 要实现可修改的映射,程序员必须额外覆盖该类的put方法(否则会抛出一个UnsupportedOperationException)entrySet().iterator()返回的迭代器必须额外实现它的remove方法。

<p>The programmer should generally provide a void (no argument) and map
constructor, as per the recommendation in the <tt>Map</tt> interface
specification.

按照map接口规范中的建议,程序员通常应该提供一个void(无参数)map构造函数。

<p>The documentation for each non-abstract method in this class describes its
implementation in detail.  Each of these methods may be overridden if the
map being implemented admits a more efficient implementation.

该类中每个非抽象方法的文档详细描述了其实现。如果正在实现的映射允许更有效的实现,则可以覆盖这些方法。