I'm having some trouble in the following code.
public ArrayList<? extends IEvent> getEventsByDateRange(DateTime minStartTime, DateTime minEndTime)
{
ArrayList<? extends IEvent> returnedEvents = new ArrayList<GoogleEvent>();
returnedEvents.add(new GoogleEvent());
return (returnedEvents);
}
This return the following compilation error for the "returnedEvents.add(new GoogleEvent()); line of code":
The method add(capture#1-of ? extends IEvent) in the type ArrayList is not applicable for the arguments (GoogleEvent)
The declaration of the class GoogleEvent
is as follows:
public class GoogleEvent implements IEvent {...}
I know there are some tricky parts using generics in Java, thus the wild-cards but I can't seem to figure this out.
Thanks.
Why don't you write: