@FunctionalInterface
public interface GenericFunctionalInterface {
public <T> T genericMethod();
}
I have above @FunctionalInterface and it has a generic method.
How can I use and Lambda expression to represent this Interface?
I tried below code, but it doesn't work,
GenericFunctionalInterface gfi = () -> {return "sss";};
I got compile error: Illegal lambda expression: Method genericMethod of type GenericFunctionalInterface is generic
Where can I place the type info?
The generic (not genetic) type parameter should be declared in the interface level, not in the method level :
public interface GenericFunctionalInterface<T> {
public T genericMethod();
}
GenericFunctionalInterface<String> gfi = () -> {return "sss";};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With