United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 5043025 Access to Field, Method and Constructor without the use of Strings
5043025 : Access to Field, Method and Constructor without the use of Strings

Details
Type:
Enhancement
Submit Date:
2004-05-06
Status:
Open
Updated Date:
2009-06-18
Project Name:
JDK
Resolved Date:
Component:
specification
OS:
windows_vista,linux,generic,solaris_10,windows_xp,windows_2000
Sub-Component:
language
CPU:
x86,sparc,generic
Priority:
P4
Resolution:
Unresolved
Affected Versions:
1.4.0,1.4.1,1.4.2,5.0,6,7
Targeted Versions:

Related Reports
Duplicate:
Duplicate:
Duplicate:
Duplicate:
Duplicate:
Duplicate:
Duplicate:
Duplicate:
Duplicate:

Sub Tasks

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
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.

------]
                                     
2006-11-15
EVALUATION

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



Hardware and Software, Engineered to Work Together