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!

Recommended Answers

All 2 Replies

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));
    }
commented: Helpful! +9

Yep, that solved my question. Thank you very much!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.