• Post Reply Bookmark Topic Watch Topic
  • New Topic

Doubt regarding PriorityQueue Example  RSS feed

 
Mansukhdeep Thind
Ranch Hand
Posts: 1163
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
Please look at the code below:



It is throwing compilation error
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The type PriorityQueue is not generic; it cannot be parameterized with arguments <Integer>
The type PriorityQueue is not generic; it cannot be parameterized with arguments <Integer>
The type PriorityQueue is not generic; it cannot be parameterized with arguments <Integer>
The type PriorityQueue is not generic; it cannot be parameterized with arguments <Integer>
Syntax error on token "pqs", delete this token

at com.mansukh.test.PriorityQueue.main(PriorityQueue.java:13)


Why is this happening as in the book it says that PriorityQueues can use Generics?(This example is from Generics chapter in SCJP book)

Regards
Mansukhdeep
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which PriorityQueue class do you think you are using ? Hint : check the name of your main class.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1163
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe Verré wrote:Which PriorityQueue class do you think you are using ? Hint : check the name of your main class.


Thanks Chris. One more doubt. Can you please explain what exactly does the Comparator defined here do? When is it called and how does the compare function work.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A queue has its elements ordered to their natural ordering. You may wish to order them differently, by using a Comparator. You'll find a tutorial on comparators here.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!