9. สร้างใหม่จากเก่า

The Camtasia Studio video content presented here requires JavaScript to be enabled and the latest version of the Macromedia Flash Player. If you are you using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Flash Player by downloading here.

 
รหัสที่ 9-23  เมท็อด equals และ toString ที่ปรากฏในคลาส Object
package java.lang;

public class Object {
  ...
  // คืนผลการเปรียบเทียบว่า อ็อบเจกต์ obj “เท่ากับ” อ็อบเจกต์ this หรือไม่ 
  public boolean equals(Object obj) {
    return this == obj;  
  }
  // คืนสตริงที่แทนค่าของอ็อบเจกต์ this
  public String toString() {
    return this.getClass().getName() + "@" +
           Integer.toHexString(hashCode());
  }
  ...
}
©2009 S.Prasitjutrakul