??????????????°汾??Point???ColoredPoint???屣??????淶??????????????????????Point??ColoredPoint?????????false???????p???????cp??“p.equals(cp)?????????????????cp.canEqual(p)?????false?????????cp.equals(p)????????false??????p???????ColoredPoint????????ColoredPoint??equals?????????????instanceof?????????

??????????????棬?????Point????????????????????????????????????????????????????????????????壬p??pAnon??????????true?????????Щ?????

Point p = new Point(1?? 2);

ColoredPoint cp = new ColoredPoint(1?? 2?? Color.INDIGO);

Point pAnon = new Point(1?? 1) {
    @Override public int getY() {
        return 2;
    }
};

Set<Point> coll = new java.util.HashSet<Point>();
coll.add(p);

System.out.println(coll.contains(p)); // ??? true

System.out.println(coll.contains(cp)); // ??? false

System.out.println(coll.contains(pAnon)); // ??? true

??????Щ??????????????????equals???????岢??????canEquals????????????????????????????????????????????????????б???????ColoredPoint?????????”???????????????????????????????????????” canEqual???????????????????????pAnon????????????????????canEqual?????????????????Point????????ж???

????canEqual????????????????????????Υ????Liskov?滻???(LSP)?????磬??????????????????????????(??????? canEqual?????汾?????.getClass()??????汾)???????2???????????????????????????????丸????б??????Υ????LSP???????????LSP???????????????κ?????????????????????????????滻?????????????У????cp??x??y?????????Щ??????е?????”coll.contains(cp)”???????false???????????Υ??????LSP???????????????????Point??????????ColoredPointed??????????????????????????????LSP???????????????????????£???????????????????????????淶??

???????????????????????дequals????(??????? canEqual?????汾?????.getClass()??????汾)??????????Υ??LSP????????????????????????????????????????????????????ж????????????磬?????????????????????????????”coll.contains(pAnon)”??????false???????????????????????????????“coll.contains(cp)”????false??????????ColoredPoint???????equals????????????????????????1??2???????????????1??2????????????????????????????????У??????????Point???????????????????????contains?????????????????????????????????????????????????

????–?????–