2

Please consider this an attempt to understand the api and not questioning the judgement of the architect.

JavaFX Event

Referring to the constructor of the javafx.event.Event, I need to pass an EventType of Event to instantiate an Event. Am I reading this right ? If so, wouldn't this be a cyclic reference ?

ShaggyInjun
  • 2,880
  • 2
  • 31
  • 52
  • As far as I see on the API docs, Event depends on EventType, but EventType does not depend on Event, so there is no cyclic reference. – Guillaume Jan 31 '13 at 04:06

3 Answers3

3

No its not, because generic parameters are resolved at compile time. At runtime there's nothing being passed into the Event constructor but an EventType.

Perception
  • 79,279
  • 19
  • 185
  • 195
2

Not in the sense that you mean.

An EventType instance can refer to other EventType instances, but not to Event instances. Take a look at the constructor and methods of EventType, paying close attention to the method / constructor parameter and return types.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
1

This is not cyclical, but it really, really takes a lot of thinking to understand.

From the javadoc you provided:

Event(EventType<? extends Event> eventType) 
Construct a new Event with the specified event type.

The EventType<? extends Event> should be read as "An EventType that works with a certain type of Event".

Here is another SO answer that does a better job of explaining the <? extends Class>: https://stackoverflow.com/a/3009779/463196

For example, let's say we have a FooEvent that extends Event. We would then have an EventType that works with FooEvent.

Also, if you look at the JavaDoc for EventType, it says:

This class represents a specific event type associated with an Event. 
Community
  • 1
  • 1
Philip Tenn
  • 6,003
  • 8
  • 48
  • 85