• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Help please

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much, Stan!

Vlada
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Is this the real life? Is this just fantasy? Is this a tiny ad?
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic