instead of using anonymous classes like so
register(new EventListener() {
@Override
public void apply(Event e) {
// do your work
}
});
with java 8 I can use lambda expressions:
register(e -> (// do your work));
But what if the method in my interface is annotated?
interface EventListener {
@Annotation
void apply;
}
Is it possible to annotate a lambda expression? (Specifically, I want to use Guava's EventBus.register() method with lambda expressions)
See this:
Annotating the functional interface of a Lambda Expression
Basically, you can't directly annotate in a lambda expression, but you can use the extending interface or class and access the annotation by calling Class#getAnnotatedInterfaces()
. I believe that should answer your question.
Hope this helps,
Santiago
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