6

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)

S1lentSt0rm
  • 1,989
  • 2
  • 17
  • 28

1 Answers1

3

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

Community
  • 1
  • 1
Santiago Benoit
  • 994
  • 1
  • 8
  • 22