Important: The information in this document is obsolete and should not be used for new development.
Inherits from | Object |
Implements | |
Package | com.apple.cocoa.foundation |
Companion guide |
NSObject is the root class of most Objective-C class hierarchies. NSObject, along with java.lang.Object, is the root class for all things Cocoa in Java.
Creates an NSObject. You should create instances of concrete subclasses instead of NSObject.
public NSObject
()
Returns a new instance that’s a copy of the receiver.
public Object clone
()
The copy returned is immutable if applicable to the receiver; otherwise the exact nature of the copy is determined by the class. Throws java.lang.CloneNotSupportedException
.
Returns true
if the receiver and anObject are equal, false
otherwise.
public boolean equals
(Object anObject)
NSObject’s implementation compares the id of anObject and the receiver to determine equality. Subclasses can override this method to redefine what it means for objects to be equal. For example, a container object might define two containers as equal if they contain the same contents. See the NSData, NSDictionary, NSArray, and java.lang.String
class specifications for examples of the use of this method. If subclasses override equals
, they must also override hashCode
to ensure that all objects that return true
for equals
also return the same value for hashCode
. Note that equality as defined by this method is not necessarily reflexive. For example, A is equal to B does not imply B is equal to A, especially if B is a subclass of A.
Returns an integer that can be used as a table address in a hash table structure.
public int hashCode
()
NSObject’s implementation returns a value based on the object’s id. If two objects are equal (as determined by the equals
method), they must return the same hash value. This last point is particularly important if you define hashCode
in a subclass and intend to put instances of that subclass into a collection.
Returns a new instance that’s a mutable copy of the receiver. The copy returned is mutable whether the original is mutable or not.
public Object mutableClone
()
Sets the value for the property identified by key to value.
public void takeValueForKey
(Object value, String key)
The default implementation works as follows:
Searches for a public accessor method of the form set
Key, invoking it if there is one.
If a public accessor method isn’t found, searches for a private accessor method of the form _set
Key, invoking it if there is one.
If an accessor method isn’t found, takeValueForKey
searches for an instance variable based on key and sets the value directly. If the key is “lastName”, it searches for an instance variable named _lastName
or lastName
.
Returns a string that represents the contents of the receiving class.
public String toString
()
NSObject’s implementation of this method simply prints the name of the class.
Returns the value for the property identified by key.
public Object valueForKey
(String key)
The default implementation works as follows:
Searches for a public accessor method based on key. For example, with a key of “lastName”, valueForKey
looks for a method named getLastName
or lastName
.
If a public accessor method isn’t found, searches for a private accessor method based on key (a method preceded by an underbar). For example, with a key of “lastName”, valueForKey
looks for a method named _getLastName
or _lastName
.
If an accessor method isn’t found, valueForKey
searches for an instance variable based on key and returns its value directly. For the key “lastName”, this would be _lastName
or lastName
.
© 1997, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-07-24)