Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
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) ======================================================================
|