33import effectivejava .chapter3 .item10 .Color ;
44import effectivejava .chapter3 .item10 .Point ;
55
6- // Attempting to add a value component to Point (Page 41 )
6+ // Point에 값 컴포넌트(color)를 추가 (56쪽 )
77public class ColorPoint extends Point {
88 private final Color color ;
99
@@ -12,33 +12,33 @@ public ColorPoint(int x, int y, Color color) {
1212 this .color = color ;
1313 }
1414
15- // Broken - violates symmetry! (Page 41 )
15+ // 코드 10-2 잘못된 코드 - 대칭성 위배! (57쪽 )
1616 @ Override public boolean equals (Object o ) {
1717 if (!(o instanceof ColorPoint ))
1818 return false ;
1919 return super .equals (o ) && ((ColorPoint ) o ).color == color ;
2020 }
2121
22- // // Broken - violates transitivity ! (page 42 )
22+ // // 코드 10-3 잘못된 코드 - 추이성 위배 ! (57쪽 )
2323// @Override public boolean equals(Object o) {
2424// if (!(o instanceof Point))
2525// return false;
2626//
27- // // If o is a normal Point, do a color-blind comparison
27+ // // o가 일반 Point면 색상을 무시하고 비교한다.
2828// if (!(o instanceof ColorPoint))
2929// return o.equals(this);
3030//
31- // // o is a ColorPoint; do a full comparison
31+ // // o가 ColorPoint면 색상까지 비교한다.
3232// return super.equals(o) && ((ColorPoint) o).color == color;
3333// }
3434
3535 public static void main (String [] args ) {
36- // First equals function violates symmetry (Page 42 )
36+ // 첫 번째 equals 메서드(코드 10-2)는 대칭성을 위배한다. (57쪽 )
3737 Point p = new Point (1 , 2 );
3838 ColorPoint cp = new ColorPoint (1 , 2 , Color .RED );
3939 System .out .println (p .equals (cp ) + " " + cp .equals (p ));
4040
41- // Second equals function violates transitivity (Page 42 )
41+ // 두 번째 equals 메서드(코드 10-3)는 추이성을 위배한다. (57쪽 )
4242 ColorPoint p1 = new ColorPoint (1 , 2 , Color .RED );
4343 Point p2 = new Point (1 , 2 );
4444 ColorPoint p3 = new ColorPoint (1 , 2 , Color .BLUE );
0 commit comments