Implementing equals method using compareTo

前端 未结 2 1115
温柔的废话
温柔的废话 2021-01-02 01:57

General question: When implementing an override of the default equals method in Java, what concerns should I have about simply utilizing an already implemented

2条回答
  •  余生分开走
    2021-01-02 02:32

    compareTo may involve a lot more work than is necessary just to get an equality answer, which may end up being a performance issue, depending on your application usage.

    Other than that, following DRY principles it would be a good idea to re-use the code as you have suggested.

提交回复
热议问题