How to get lambda constructor return type

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

eg.

Supplier<Foo> sFoo = Foo::new;

How do I get "Foo.class" from a vendor? I used 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 designate the Supplier as:, the Supplier<Foo> sFoo = Foo::newreturn type cannot be resolved ...

Any thoughts? I do not need to use typetools btw ...

+4
source share
1 answer

, typeTools. .

, runtime . . , Class<?>.

+2

Source: https://habr.com/ru/post/1624533/


All Articles