Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8646525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:49:58+00:00 2026-06-12T12:49:58+00:00

I am implementing a priority queue of custom objects. The custom object class looks

  • 0

I am implementing a priority queue of custom objects. The custom object class looks like below,
would it be recommended to implement it as a generic class, where T simply is a payload associated with the messageId?

public class PriQMsgPayload <T> implements Comparable<PriQMsgPayload<T>>{


    private Integer mMsgNum;
    private T ExtraDataForMsg = null;

    public PriQMsgPayload(T extra, PluginConfig.PriQMessage msg)
    {
        mMsgNum= msg;
        ExtraDataForMsg = extra;
    }

    @Override
    public int compareTo(PriQMsgPayload<T> another) {
        return mMsgNum.compareTo(another.mMsgNum);
    }
}

My doubt: in below mentioned case, I first insert the P1 specialized for Integer and when I insert another object P2 which is specialized for MyClass, would the comparator not get confused?

PriQMsgPayload<Integer> P1 = new PriQMsgPayload<Integer>(2, 1);
PriQMsgPayload<MyClass> P2 = new PriQMsgPayload<MyClass>(new MyClass(), 2);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T12:49:59+00:00Added an answer on June 12, 2026 at 12:49 pm

    I don’t think there’s any point. The problem comes when you try to put the objects into the queue – there is no fully-cooked type that the queue can have which allows it to contain both of these!

    Consider:

    PriorityQueue queue; // works, but is raw
    PriorityQueue<PriQMsgPayload> queue; // works, but is partially raw
    PriorityQueue<PriQMsgPayload<Object>> queue; // won't accept either object
    

    You can put them into a queue of this type (i initially said you couldn’t, but @newacct kindly corrected me):

    PriorityQueue<PriQMsgPayload<?>> queue; // won't accept either object
    

    But that involves throwing away the type information about what kind of extra data you have.

    None of the queue types which let you add both objects preserve the type of the extra data; that means that when you got the objects out again, you would have lost all type information. There’s no way to write code that safely extracts the object as a PriQMsgPayload<Integer> rather than a PriQMsgPayload<MyClass>.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am implementing a generic Priority Queue as part of a homework project. I
How would you go about implementing a priority queue using a linked list in
Implementing a custom Dependency Property on a Framework Element object causes my Visual Studio
implementing service something similar with tinyurl or bit.ly, I'm would like to expose service
I recently took a stab at implementing a concurrent priority queue using a skip-list
I am implementing a generic class, which should behave differently for different sets of
I want to have a priority queue with custom ordering, but lazy as I
I'm implementing a simple priority queue in C for a kernel and so I
I am interested in implementing a priority queue to enable an efficient Astar implementation
so I am having trouble implementing priority queue. For a priority queue, I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.