Re: Passing a Method Name to a Method
Gene Wirchenko <genew@ocis.net> writes:
I want to pass a parameter of a method name to another method.
In Java, there is no such thing as ?a parameter of a method name?.
There are ?parameter declarations?, which are a part of a
?method declaration?. (Vulgo: ?parameters? of ?methods?
[not ?method names?]).
N.B.: I do not want to pass the method name as a string.
A method /name/ /is/ a string.
I want to pass it as a pointer / reference / whatever term is
used for this in Java.
The closest you can get is
http://download.java.net/jdk7/docs/api/java/lang/reflect/Method.html
, although you may not like it.
Or use a ?method object?, that is an object implementing
an interface with a single method, such as, for example,
http://download.java.net/jdk7/docs/api/java/lang/Runnable.html
or
http://download.java.net/jdk7/docs/api/java/util/concurrent/Callable.html
(it is called ?function object? or ?functor? in the C++ world.)
Such an object represents a methods as a run-time value.
Java 8 will have lambda expressions.