JDK-4948610 : Integrate usage of Reflection API for methods into the Java grammar
  • Type: Enhancement
  • Component: specification
  • Sub-Component: language
  • Affected Version: 1.4.2
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2003-11-04
  • Updated: 2006-11-14
  • Resolved: 2006-11-14
Related Reports
Duplicate :  
Description
Name: rmT116609			Date: 11/04/2003


A DESCRIPTION OF THE REQUEST :
I would like to be able to instantiate a Method object for a specified method in a specified class, through a simple java syntax, similar to taking the address of a function i C.

I would like to code something like: MyClass.someMethod.getMethod(), that would return the specifed Method object. In the case of method name overloading, then one would pass the class definition of the parameters to indicate which method to access, i.e.: MyClass.someMethod(int.class) would indicate the right method to access.

JUSTIFICATION :
There are many cases where using the Reflection API simplifies the code. For an example: I have a class that implements the Action Interface and provides me with an Action object that uses reflection to invoke a specific method (who's name is sent in as a paramter). This class simplifies my Swing code and actually shortens the load time of my GUI classes (since I'm not creating hundreds of subclasses for Action or Action Listeners that all need to be loaded). The only thing I do not like with this solution is that when I use the class I do something like this:
  new MyAction(someObject, "someMethod")
If I later rename the someMethod then my code will break. What I would like to do is: new MyAction(someObject, SomeClass.someMethod.getMethod()).
Now if I would change the name of the method, then I should get an error when I compile the code.
(Incident Review ID: 223156) 
======================================================================