请教一下各位大佬, api 文档中关于 Comparable 接口的这段话是什么意思,看了好几遍也没懂。

2022-03-22 13:55:12 +08:00
 lr709

For the mathematically inclined, the relation that defines the natural ordering on a given class C is:

   {(x, y) such that x.compareTo(y) <= 0}.

The quotient for this total order is:

   {(x, y) such that x.compareTo(y) == 0}.

It follows immediately from the contract for compareTo that the quotient is an equivalence relation on C, and that the natural ordering is a total order on C. When we say that a class's natural ordering is consistent with equals, we mean that the quotient for the natural ordering is the equivalence relation defined by the class's equals(Object) method:

 {(x, y) such that x.equals(y)}.
1368 次点击
所在节点    Java
2 条回复
GuuJiang
2022-03-22 16:31:17 +08:00
你看不懂是因为里面出现了大量的数学名词及概念,不用深究,如果确实感兴趣的话可以去请教数学专业的人,我简单说下粗浅的理解,可能不准确,以专业人士的结论为准
整个这一段在说的就是 natural ordering 这个全序关系里的一个商构成一个等价关系,并且这个等价关系需要和 equals 构成的等价关系保持一致,至于关系、等价关系、关系的商这些就不展开了,去翻离散数学的书吧
说人话就是,x.compareTo(y) == 0 iff x.equals(y)
lr709
2022-03-30 12:23:57 +08:00
@GuuJiang 谢谢。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/842089

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX