954,536 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Queue with instances of different subclasses

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!

msr
Newbie Poster
19 posts since Dec 2007
Reputation Points: 8
Solved Threads: 0
 

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));
    }
JamesCherrill
Posting Genius
Moderator
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

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

msr
Newbie Poster
19 posts since Dec 2007
Reputation Points: 8
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You