<legend id='oX7rM'><style id='oX7rM'><dir id='oX7rM'><q id='oX7rM'></q></dir></style></legend>

        <i id='oX7rM'><tr id='oX7rM'><dt id='oX7rM'><q id='oX7rM'><span id='oX7rM'><b id='oX7rM'><form id='oX7rM'><ins id='oX7rM'></ins><ul id='oX7rM'></ul><sub id='oX7rM'></sub></form><legend id='oX7rM'></legend><bdo id='oX7rM'><pre id='oX7rM'><center id='oX7rM'></center></pre></bdo></b><th id='oX7rM'></th></span></q></dt></tr></i><div id='oX7rM'><tfoot id='oX7rM'></tfoot><dl id='oX7rM'><fieldset id='oX7rM'></fieldset></dl></div>
        <tfoot id='oX7rM'></tfoot>
          <bdo id='oX7rM'></bdo><ul id='oX7rM'></ul>

        <small id='oX7rM'></small><noframes id='oX7rM'>

        不好的做法 - 类定义 compareTo(...) 并使用 Object.equals()

        Bad practice - Class defines compareTo(...) and uses Object.equals()(不好的做法 - 类定义 compareTo(...) 并使用 Object.equals())
          <bdo id='80sUi'></bdo><ul id='80sUi'></ul>
                <i id='80sUi'><tr id='80sUi'><dt id='80sUi'><q id='80sUi'><span id='80sUi'><b id='80sUi'><form id='80sUi'><ins id='80sUi'></ins><ul id='80sUi'></ul><sub id='80sUi'></sub></form><legend id='80sUi'></legend><bdo id='80sUi'><pre id='80sUi'><center id='80sUi'></center></pre></bdo></b><th id='80sUi'></th></span></q></dt></tr></i><div id='80sUi'><tfoot id='80sUi'></tfoot><dl id='80sUi'><fieldset id='80sUi'></fieldset></dl></div>

                  <tbody id='80sUi'></tbody>
                <tfoot id='80sUi'></tfoot>
                • <legend id='80sUi'><style id='80sUi'><dir id='80sUi'><q id='80sUi'></q></dir></style></legend>

                • <small id='80sUi'></small><noframes id='80sUi'>

                  本文介绍了不好的做法 - 类定义 compareTo(...) 并使用 Object.equals()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  想知道列出的方法需要做什么

                  Wondering what needs to be done for listed method

                   public final int compareTo(final FieldDTO o) {
                          return o.available.compareTo(this.available);
                  

                  它在第 2 行抛出异常说明不好的做法 - 类定义 compareTo(...) 并使用 Object.equals() 16 天
                  field 定义 compareTo(FieldDTO) 并使用 Object.equals()

                  its throwing exception on line 2 stating Bad practice - Class defines compareTo(...) and uses Object.equals() 16 days
                  field defines compareTo(FieldDTO) and uses Object.equals()

                  不知道我应该如何处理.提前致谢.

                  Not sure how should i handle this. Thanks in advance.

                  推荐答案

                  如果你定义 compareTo 你至少应该定义 equals

                  If you define compareTo you should at least define equals

                  boolean equals(it) { 
                    return compareTo(it) == 0; 
                  } 
                  

                  否则当你把你的对象放在 Maps 和 Sets 时你会遇到奇怪的问题.通常也定义 hashCode 是一种好习惯.

                  otherwise you will get strange problems when you put your object in Maps and Sets. It is generally good practice to also define hashCode.

                  这篇关于不好的做法 - 类定义 compareTo(...) 并使用 Object.equals()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)

                          <small id='oR9Ae'></small><noframes id='oR9Ae'>

                            <tbody id='oR9Ae'></tbody>

                          <legend id='oR9Ae'><style id='oR9Ae'><dir id='oR9Ae'><q id='oR9Ae'></q></dir></style></legend>
                          <tfoot id='oR9Ae'></tfoot>
                            <bdo id='oR9Ae'></bdo><ul id='oR9Ae'></ul>
                          • <i id='oR9Ae'><tr id='oR9Ae'><dt id='oR9Ae'><q id='oR9Ae'><span id='oR9Ae'><b id='oR9Ae'><form id='oR9Ae'><ins id='oR9Ae'></ins><ul id='oR9Ae'></ul><sub id='oR9Ae'></sub></form><legend id='oR9Ae'></legend><bdo id='oR9Ae'><pre id='oR9Ae'><center id='oR9Ae'></center></pre></bdo></b><th id='oR9Ae'></th></span></q></dt></tr></i><div id='oR9Ae'><tfoot id='oR9Ae'></tfoot><dl id='oR9Ae'><fieldset id='oR9Ae'></fieldset></dl></div>