Package java.lang
Class Object
- java.lang.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 ofObject
.
-
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 ofClass
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.
-
-
-
Method Detail
-
hashCode
public int hashCode()
Returns an integer hash code for this object. By contract, any two objects for whichequals(java.lang.Object)
returnstrue
must return the same hash code value. This means that subclasses ofObject
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 ownhashCode
method.- Returns:
- this object's hash code.
- See Also:
equals(java.lang.Object)
-
getClass
public final Class<?> getClass()
Returns the unique instance ofClass
that represents this object's class. Note thatgetClass()
is a special case in that it actually returnsClass<? extends Foo>
whereFoo
is 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
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 ifthis == o
. See Writing a correctequals
method if you intend implementing your ownequals
method.The general contract for the
equals
andhashCode()
methods is that ifequals
returnstrue
for any two objects, thenhashCode()
must return the same value for these objects. This means that subclasses ofObject
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 thisObject
;false
otherwise.- See Also:
hashCode()
-
-