In the following code:
interface Callback {
void greet(String greeting);
}
private static <T extends Callback & Serializable> void greetMe(T callback) {
callback.greet("Hello world!");
}
public static void main(String[] args) {
greetMe(greeting -> System.out.println(greeting));
}
The following line does not compile, because the lambda is not Serializable:
greetMe(greeting -> System.out.println(greeting));
My question is, is there any syntactic sugar for making the lambda implement Serializable, or do I have to make it a non-anonymous class?