Package java.lang

Class Object


  • public class Object
    The root class of the Java class hierarchy. All non-primitive types (including arrays) inherit either directly or indirectly from this class. This class is only partly implemented as we currently have no reflection and synchronization
    • Constructor Summary

      Constructors 
      Constructor Description
      Object()
      Constructs a new instance of Object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(Object o)
      Compares this instance with the specified object and indicates if they are equal.
      Class<?> getClass()
      Returns the unique instance of Class that represents this object's class.
      int hashCode()
      Returns an integer hash code for this object.
      String toString()
      Returns a string containing a concise, human-readable description of this object.
    • Constructor Detail

      • Object

        public Object()
        Constructs a new instance of Object.
    • Method Detail

      • hashCode

        public int hashCode()
        Returns an integer hash code for this object. By contract, any two objects for which equals(java.lang.Object) returns true must return the same hash code value. This means that subclasses of Object usually override both methods or neither method.

        Note that hash values must not change over time unless information used in equals comparisons also changes.

        See Writing a correct hashCode method if you intend implementing your own hashCode method.

        Returns:
        this object's hash code.
        See Also:
        equals(java.lang.Object)
      • getClass

        public final Class<?> getClass()
        Returns the unique instance of Class that represents this object's class. Note that getClass() is a special case in that it actually returns Class<? extends Foo> where Foo is the erasure of the type of the expression getClass() was called upon.

        As an example, the following code actually compiles, although one might think it shouldn't:

        
           List<Integer> l = new ArrayList<Integer>();
           Class<? extends List> c = l.getClass();
        Returns:
        this object's Class instance.
      • toString

        public String toString()
        Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data.
        Returns:
        a printable representation of this object.
      • equals

        public boolean equals​(Object o)
        Compares this instance with the specified object and indicates if they are equal. In order to be equal, o must represent the same object as this instance using a class-specific comparison. The general contract is that this comparison should be reflexive, symmetric, and transitive. Also, no object reference other than null is equal to null.

        The default implementation returns true only if this == o. See Writing a correct equals method if you intend implementing your own equals method.

        The general contract for the equals and hashCode() methods is that if equals returns true for any two objects, then hashCode() must return the same value for these objects. This means that subclasses of Object usually override either both methods or neither of them.

        Parameters:
        o - the object to compare this instance with.
        Returns:
        true if the specified object is equal to this Object; false otherwise.
        See Also:
        hashCode()