Package java.lang
Class Object
- java.lang.Object
-
public class ObjectThe 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 ofObject.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)Compares this instance with the specified object and indicates if they are equal.Class<?>getClass()Returns the unique instance ofClassthat represents this object's class.inthashCode()Returns an integer hash code for this object.StringtoString()Returns a string containing a concise, human-readable description of this object.
-
-
-
Method Detail
-
hashCode
public int hashCode()
Returns an integer hash code for this object. By contract, any two objects for whichequals(java.lang.Object)returnstruemust return the same hash code value. This means that subclasses ofObjectusually 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
hashCodemethod if you intend implementing your ownhashCodemethod.- Returns:
- this object's hash code.
- See Also:
equals(java.lang.Object)
-
getClass
public final Class<?> getClass()
Returns the unique instance ofClassthat represents this object's class. Note thatgetClass()is a special case in that it actually returnsClass<? extends Foo>whereFoois the erasure of the type of the expressiongetClass()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
Classinstance.
-
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,omust 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
trueonly ifthis == o. See Writing a correctequalsmethod if you intend implementing your ownequalsmethod.The general contract for the
equalsandhashCode()methods is that ifequalsreturnstruefor any two objects, thenhashCode()must return the same value for these objects. This means that subclasses ofObjectusually override either both methods or neither of them.- Parameters:
o- the object to compare this instance with.- Returns:
trueif the specified object is equal to thisObject;falseotherwise.- See Also:
hashCode()
-
-