vendredi 15 janvier 2016

How to get return type of constructor lambda

I was wondering if it is possible to get the return type of a Supplier that was assigned to a constructor.

E.g.

Supplier<Foo> sFoo = Foo::new;

How do I get "Foo.class" from the supplier? I have been using typetools to solve this problem for other things.

This works, for example:

Supplier<Foo> sFoo = () -> new Foo();
Class<?> fooClasss = net.jodah.typetools.TypeResolver.resolveRawArguments(Supplier.class, sFoo.getClass())[0];
// fooClass == Foo.class

But if I assign Supplier like: Supplier<Foo> sFoo = Foo::new, the return type cannot be resolved...

Any thoughts? I don't have to use typetools btw...





Aucun commentaire:

Enregistrer un commentaire