• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help please  RSS feed

 
Vlada Den
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am trying to compile a program, but get the following error message: "Queue is abstract; cannot be instantiated
empty_queue = new Queue();".

Here is the code:




Thanks in advance,

Vlada
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look up Queue in the javadoc. It is an interface which is a contract that tells you the methods any implementing class must have, but isn't a class you can instantiate.

So, what can you create? In the doc is a section called All Known Implementing Classes. You can put any concrete (not abstract) classes in that list in your new clause.

Queue myQueue = new LinkedBlockingQueue().

How do you decide which of those to use? Put your feet up, read the doc on each one and see which fits your needs the best.

Any code that uses Queue, say as a parameter, will accept any of those implementing classes, which is pretty slick. So if you can, write all of your code except the instantiation code to reference Queue only. In real life systems that makes code much easier to live with over time; in school work and tiny programs it's just good practice.

Lemme know if that helps!
 
Vlada Den
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much, Stan!

Vlada
 
Matt Fielder
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it would be helpful to use a topic that helped other find this if they were searching later for the same information.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!