无感升级中的一点思考

必须重写CompatibilityTestDO 的equals方法,保险起见重写hashCode方法。
LinkedList的remove方法要调用equals方法。

  1. public boolean remove(Object o) {
  2. if (o == null) {
  3. for (Node<E> x = first; x != null; x = x.next) {
  4. if (x.item == null) {
  5. unlink(x);
  6. return true;
  7. }
  8. }
  9. } else {
  10. for (Node<E> x = first; x != null; x = x.next) {
  11. //x.item是链表中的element
  12. if (o.equals(x.item)) {
  13. unlink(x);
  14. return true;
  15. }
  16. }
  17. }
  18. return false;
  19. }