一、原文与翻译
public interface CharSequence
A CharSequence is a readable sequence of char values. This interface provides uniform, read-only access to many different kinds of char sequences. A char value represents a character in the Basic Multilingual Plane (BMP) or a surrogate. Refer to Unicode Character Representation for details.
CharSequence 是一个可读的字符值的序列。这个接口为许多不同种类的字符序列提供了统一的,只读的通道。一个字符值代表了在基本多文种平面或它的代理里的一个字符。参考Unicode字符表示。
This interface does not refine the general contracts of the equals and hashCode methods. The result of comparing two objects that implement CharSequence is therefore, in general, undefined.
这个接口没有细化 equals 和 hashCode 方法的通用约定。因此实现了 CharSequence 接口的两个对象间的比较结果一般是不确定的。
Each object may be implemented by a different class, and there is no guarantee that each class will be capable of testing its instances for equality with those of the other. It is therefore inappropriate to use arbitrary CharSequence instances as elements in a set or as keys in a map.
每个对象可能被不同的类实现,并不保证每个类能够检测出它的实例和另一个类的实例的相等性。因此,随意使用 CharSequence 实例作为 set 集合的元素或者作为 map 的 key 都是不合适的。
Since: 1.4
自:1.4
二、词汇学习
Multilingual
: 使用多语言的
surrogate
: 代理,替代
inappropriate
: 不适当的
arbitrary
: 任意的
三、句子分析
- The result of comparing two objects that implement CharSequence is therefore, in general, undefined.*
主干:The result is undefined.
找出句子主干后,句子意思就好理解了。result 后面的一连串内容都是描述这是什么样的结果。
四、技术要点
由于接口并没有约定 equals 和 hashCode 的实现方法,而 set 的元素和 map 的 key 是通过 equals 和 hashCode 方法来判断两个元素是否相等的,因此不能使用不同类的实例来作为 set 的元素和 map 的 key,否则可能会产生不可预料的后果。
微信公众号.jpg
网友评论