1 / 7

The Object class

The Object class. Object. package java.lang. !. aCopy. Object. clone. toThis. equals. yesOrNo. hash. hashCode. string. toString. The Object class from the JDK documentation 1. java.lang.Object public class Object

Télécharger la présentation

The Object class

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Object class Object package java.lang ! aCopy Object clone toThis equals yesOrNo hash hashCode string toString

  2. The Object class from the JDK documentation 1 java.lang.Object public class Object Class Object is the root of the class hierarchy. Every class has Object as a superclass. All objects, including arrays, implement the methods of this class. Objects are part of the standard class libraries, not part of the language itself (well not really….)

  3. The Object class from the JDK documentation 2 protected Object clone() throws CloneNotSupportedException Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class ... In practice most developers have supplied a constructor which takes an instance of the class as an argument instead . . . … and use this instead of clone() public Object( Object toCopy)

  4. The Object class from the JDK documentation 3 public boolean equals( Object toThis) Indicates whether some other object is "equal to" this one... Two instances are equal if they have the same state … even if they are not the same object! Remember object identity & object equality!

  5. The Object class from the JDK documentation 4 public int hashCode() Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable This is vital for hashtable collections and they are sufficiently important to require that this method is included in Object. (A hash value is a means of supplying a non-unique key value for key-value pair storage!)

  6. The Object class from the JDK documentation 4 public int hashCode() Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable This is vital for hashtable collections and they are sufficiently important to require that this method is included in Object. (A hash value is a means of supplying a non-unique key value for key-value pair storage!)

  7. The Object class from the JDK documentation 5 public String toString() Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. Actually it is recommended that all subclasses override all 4 methods specified.

More Related