JDK-6356762 : Should be possible to aquire Method object without reflection
  • Type: Enhancement
  • Component: specification
  • Sub-Component: language
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-11-30
  • Updated: 2010-04-04
  • Resolved: 2006-11-14
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE REQUEST :
At the moment, the only way to get Method and Field objects is via reflection.  Unfortuantely, all reflection methods dealing with these objects require String names of the methods and fields desired.  This makes it impossible to obfuscate such code, since the method names will change under obfuscation but the String names will not.

Instead, it would be useful for the Java language to return a special object to represent method declarations.  For example:

    MethodNamePart methNamePart = String.class.toString;

or

    File file = new File(".");
    MethodNamePart methNamePart = file.exists;

One could then convert this into a Method by an extra method added to Class:

    Method method = File.class.getMethod(methNamePart , new Class[]);
    

JUSTIFICATION :
At the moment, there is no way to obtain Method and Field objects under reflection if the code is obfuscated.  By adding this feature to the compiler and engine, this will no longer be a problem.

The MethodNamePart class would also provide a useful and unambigious way of referring to only the name portion of the method.