dimanche 15 février 2015

Java 8 find getter name from method reference

In some expermients I'd like to write something like this:



query(Person.class, eq(Person::lastName, "Hawking"));


where eq method creates database query part lastName = 'Hawking' and query as a result return String "SELECT * FROM person WHERE lastName = 'Hawking'". This way I'd be able to write type safe queries with short form and without code generation.


Problem is that eq as first parameter takes Supplier<E>.


Is it possible to find out via reflection API method name from passed method reference?


Even hackish way allowed! :)






Aucun commentaire:

Enregistrer un commentaire