0

Hello,

I would like to have a PriorityQueue whose elementes are instances of different subclasses.

For example:
Event is an abstract superclass.
Event1, Event2, Event3 are subclasses.
Xpto<> is an interface and PriorityQueueXpto<> is a class that implements Xpto and extends PriorityQueue.

Xpto<? extends Event> a = new PriorityQueueXpto<????>();

Is this possible? How?

Thank you in advance!

Edited by msr: n/a

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by msr
2

I see no-one has replied to this (wonder why???), so I'll have a go.
Is the following the kind of thing you are looking for?

interface I<T extends Event> {
      T dosomething(T t);
   }
   
   class Event2 extends Event {

      public Event2(Object arg0, int arg1, Object arg2) {
         super(arg0, arg1, arg2);
      }
   }
   
   class C<T extends Event> extends PriorityQueue implements I<T> {

      @Override
      public T dosomething(Event t) {
         // TODO Auto-generated method stub
         return null;
      }
      
   }
    void test() {
       I<Event2> c = new C<Event2>();
       c.dosomething(new Event2(null, 0, null));
    }

Edited by JamesCherrill: Improved sample code

Votes + Comments
Helpful!
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.