Reflection syntax sugar
Rémi Forax
forax at univ-mlv.fr
Fri Nov 18 11:32:49 PST 2011
JDK8 will include a method reference syntax which can be seen
as a typesafe way to handle a reference to a method.
By example,
Runnable runnable = "foo"::length;
should compile.
The slide from Brian Goetz explaining lambda and method reference is
available here:
http://blogs.oracle.com/briangoetz/entry/slides_from_devoxx_talk_on
You can test a prototype here:
http://jdk8.java.net/lambda/
(the syntax implemented in the prototype for method reference use '#'
instead of '::')
Compared to reflection a method reference/lambda call through
a functional interface should be faster than using the reflection
(at least until the reflection is rewritten to use the same mechanism
as the one used for implementing lambda).
No syntax for typesafe property will be not included in jdk8,
perhaps in 9 when JavaFX will be merged in the jdk.
cheers,
Rémi
On 11/18/2011 07:16 PM, Matthew Adams wrote:
> Hi all,
>
> I'm hoping that reflection syntax sugar enhancements can make it into JDK8.
>
> It appears the consolidated issue, referencing several others& which looks
> the most promising IMHO, is at
> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5043025
>
> It uses the javadoc-like syntax, primary the # operator, with some other
> suggestions by me& others. I entered my own issue that was closed as a
> duplicate of 5043025:
> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6915224
>
> One thing about my request that deserves discussion is whether it's a
> compile-time error if the fields, annotations, constructors& methods
> referred to are not present. I was thinking that it should be selectable
> by the developer, but then it would require a new @SupressErrors annotation
> (like @SupressWarnings). That might open up a can of worms, though.
>
> Please review the issues above and those reachable from them. Is this
> feasible? It has good application in the area of query in JDO, JPA&
> others.
>
> Thanks,
> Matthew
More information about the jdk8-dev
mailing list