Important: The information in this document is obsolete and should not be used for new development.
Inherits from | Object |
Package | com.apple.cocoa.foundation |
Companion guide |
An NSSelector object (also called a selector) specifies a method signature, which is a method’s name and parameter list. You can later apply a selector on any object, and it performs the method that matches the selector, if there is one.
NSSelector is the Java implementation of the Objective-C type SEL
, described in the “Selectors” section of The Objective-C Programming Language.
For details on using NSSelector, see “Method Selectors” and “Using NSSelector”.
equals
implementedByClass
implementedByObject
methodOnClass
methodOnObject
name
parameterTypes
toString
Deprecated.
public NSSelector
(String methodName)
Creates a selector for the method that's named methodName and takes parameters parameterTypes.
public NSSelector
(String methodName, Class[] parameterTypes)
To create a selector for a method that takes no arguments, use null
for parameterTypes. For an example, see “Using NSSelector”.
public static Object invoke
(String methodName, Class[] parameterTypes, Object target, Object[] arguments)
Creates and applies a selector that has any number of arguments. This method creates a selector with methodName and the parameter types in the array parameterTypes, applies that selector to target with the arguments in the array arguments, and returns the result. To apply a method that takes no arguments, use null
for the arrays parameterTypes and arguments. As part of its implementation, this method uses the NSSelector constructor and the instance method invoke
. For more information, see those method descriptions.
public static Object invoke
(String methodName, Class parameterType, Object target, Object argument)
Creates and applies a selector that has one argument. This method creates a selector with methodName and parameterType, applies that selector to target with argument, and returns the result. As part of its implementation, this method uses the NSSelector constructor and the instance method invoke
. For more information, see those method descriptions.
public static Object invoke
(String methodName, Class parameterType1, Class parameterType2, Object target, Object argument1, Object argument2)
Creates and applies a selector that has two arguments. This method creates a selector with methodName and the parameter types parameterType1 and parameterType2, applies that selector to target with the arguments argument1 and argument2, and returns the result. As part of its implementation, this method uses the NSSelector constructor and the instance method invoke
. For more information, see those method descriptions.
Returns whether anObject equals the method that matches the receiver.
public boolean equals
(Object anObject)
Returns whether the class targetClass implements a method that matches the receiver.
public boolean implementedByClass
(Class targetClass)
Returns whether the object target implements a method that matches the receiver.
public boolean implementedByObject
(Object target)
As part of its implementation, this method uses implementedByClass
.
public Object invoke
(Object target, Object[] arguments)
Invokes the method specified by the receiver on target with arguments and returns the result. If that method is void
, it returns null
. Note that the method may be a static or instance method.
The invoke
method can’t handle arguments or return values of primitive types (such as boolean, int, or float). If the method matching the selector returns a value of a primitive type, invoke
returns the value in an object of the corresponding wrapper type (such as Boolean, Integer, or Float). To pass an argument of a primitive type to invoke
, use an object of the corresponding wrapper class. invoke
converts the object back to the primitive type when it invokes the method.
invoke
throws an exception in the following cases:
If target has no method that matches the selector, it throws NoSuchMethodException
.
If a method matches the selector but is inaccessible to target, it throws IllegalAccessException
.
If it can’t convert an argument to the type specified in the selector, it throws IllegalArgumentException
.
If the invoked method throws an exception, it wraps that exception in a java.lang.reflect.InvocationTargetException
and throws the new exception without completing.
As part of its implementation, this method uses methodOnClass
.
For an example, see “Using NSSelector”.
public Object invoke
(Object target)
Invokes the method specified by the selector on target with no arguments and returns the result. If that method is void
, it returns null
. Note that the method may be a static or instance method.
As part of its implementation, this method calls the invoke
instance method which takes an array of arguments. For more information, see that method’s description.
public Object invoke
(Object target, Object argument)
Invokes the method specified by the receiver on target with one argument (argument) and returns the result. If that method is void
, it returns null
. Note that the method may be a static or instance method.
As part of its implementation, this method calls the invoke
instance method, which takes an array of arguments. For more information, see that method’s description.
public Object invoke
(Object target, Object argument1, Object argument2)
Invokes the method specified by the receiver on target with two arguments (argument1 and argument2) and returns the result. If that method is void
, it returns null
. Note that the method may be a static or instance method.
As part of its implementation, this method calls the invoke
instance method, which takes an array of arguments. For more information, see that method’s description.
Returns the method on the class targetClass that matches the receiver. If targetClass has no method that matches the receiver, this method throws NoSuchMethodException
.
public java.lang.reflect.Method methodOnClass
(Class targetClass)
Returns the method on the object target that matches the receiver. If target has no method that matches the receiver, this method throws NoSuchMethodException
.
public java.lang.reflect.Method methodOnObject
(Object target)
Returns the name of the method specified by the receiver.
public String name
()
Copies and returns the array of parameter types specified by the receiver.
public Class[] parameterTypes
()
Returns a string containing the receiver’s class (“NSSelector”) and the name of the method the receiver specifies.
public String toString
()
© 1997, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-07-24)