JDK-5043025 : Access to Field, Method and Constructor without the use of Strings
  • Type: Enhancement
  • Component: specification
  • Sub-Component: language
  • Affected Version: 1.4.0,1.4.1,1.4.2,5.0,6,7
  • Priority: P4
  • Status: Closed
  • Resolution: Other
  • OS:
    generic,linux,solaris_10,windows_2000,windows_xp,windows_vista generic,linux,solaris_10,windows_2000,windows_xp,windows_vista
  • CPU: generic,x86,sparc
  • Submitted: 2004-05-06
  • Updated: 2014-10-17
  • Resolved: 2014-10-17
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Description
Name: gm110360			Date: 05/05/2004


A DESCRIPTION OF THE REQUEST :
It should be possible to obtain references to Field, Method and
Constructor objects without the use of strings. Proposed syntax:

// Assuming the following class
public class Foo {

    String bar;

    public Foo(String bar) {
        this.bar = bar;
    }

    public void fly(String to) {
        bar = to;
    }
}

Field fooBarField = Foo.class.bar.field;
Method fooFlyMethod = Foo.class.fly.method(new Object[]{String.class});
Constructor fooConstructor = Foo.class.constructor(new Object[]{String.class});


The construct is similar to the ClassName.class syntax and it can be treated
by the Compiler in the same way:
It could produce the getDeclaredField, getDeclaredMethod and getConstructor
bytecode. No modifications to the JVM would be necessary.


JUSTIFICATION :
I posted this as an RFE twice before. The last time I was asked me to resubmit the RFE with a link to the message ID. Here is the discussion in a newsgroup:
news:bkc2ml$qdt$01$###@###.###

My justification again:
The existance of the field/method/constructor could be checked during compile
time. Typos would no longer be possible.

A notation without strings could be very easily refactored by IDEs.

We would specifically need the feature for our typesafe querying system,
so it could work completely without strings.
http://sodaquery.sf.net/

The possibility to get Method objects without strings, would encourage many
developers to use them for more dynamic programming and would result in lots
of more flexible libraries for the Java platform.

Thanks in advance for a consideration to add this very simple compiler add-on to J2SE 1.5.
(Incident Review ID: 208397) 
======================================================================

Comments
The 'specification' component of the Java Bug System is for reporting technical errors and ambiguities in the text of The Java Language Specification and The JVM Specification. It is not the venue to propose new features in the Java language or JVM. Ongoing feature development is carried out in OpenJDK (http://openjdk.java.net/jeps/); corresponding enhancements to The Java Language Specification and The JVM Specification are managed through the Java Community Process (http://jcp.org/).
17-10-2014

EVALUATION [------ This is by no means an endorsement of this feature. The syntax could be: Type . class . Identifier Type . class . Identifier ( ActualTypeArgumentList_opt ) The first form represent a field and has the compile-time type java.lang.reflect.Field. The second represent method and has the compile-time type java.lang.reflect.Method. It is a compile-time error if the ActualTypeArgumentList includes wildcard type arguments. ------]
15-11-2006

EVALUATION The 'master' request for easier reflection.
14-11-2006