Reﬂective access to parameter names
Practical experience with annotations has identiﬁed situations in which it’d be useful to be able to access the names of method and constructor parameter names. This is particularly relevant to JSRs 181 (Web-Services Metadata) and 224 (JAX-WS 2.0), but it may also be of use in other JSRs such as 255(JMX 2.0) and 274 (Design-Time API for JavaBeans).
This feature will provide access to the names of constructor and method parameters at runtime via the reﬂection API. To do this effectively will probably require the introduction of a new core annotation, or perhaps a meta-annotation, to identify constructors and methods whose parameter names should be recorded in class ﬁles. Otherwise this feature would only work with class ﬁles containing full debug information; such class ﬁles are larger than is desirable in production settings.
The JSR 270 Expert Group concluded, after a lengthy discussion, that it would be better to support reﬂective access to all parameter names, by default, rather than require the use of annotations or some other means to request that parameter names be recorded during the compilation of particular classes or interfaces. This is the cleanest approach from the standpoint of language design, it ﬁlls in one last gap in Java’s reﬂection facilities, and it removes any question as to whether or not parameter names will be available to applications.
A consequence of making parameter names available by default is that programs may, intentionally or not, become dependent upon parameter names even though such names are not, strictly speaking, part of the signature of a constructor or method. After this change is made it will be dangerous to rename a parameter of any public or protected method or constructor in any published API. A change of this magnitude deserves wider, and longer-term, publicity and discussion than is possible in the remainder of the Java SE 6 development cycle. The JSR 270 EG therefore recommends that this more complete approach be pursued in Java SE 7.