0

Following the code example for Otto, when an event is produced, an event class is returned from the producer function:

@Produce public AnswerAvailableEvent produceAnswer() {
    // Assuming 'lastAnswer' exists.
    return new AnswerAvailableEvent(this.lastAnswer);
}

However, the AnswerAvailableEvent does not seem to be defined anywhere. The only other times it is mentioned in the documentation is when the event is posted

bus.post(new AnswerAvailableEvent(42));

and when the event is received:

@Subscribe public void answerAvailable(AnswerAvailableEvent event) { ... }

Is this class automagically defined somehow? how does the class know what to do with the this.lastAnswer parameter?

Thanks.

Zerp
  • 874
  • 2
  • 8
  • 18

1 Answers1

1

Is this class automagically defined somehow?

No. It is something that you write, named whatever you want, holding onto whatever event data that you want.

how does the class know what to do with the this.lastAnswer parameter?

That is a constructor parameter. When you write your event class, you can implement whatever constructors make sense to you.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491