• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Cannot instantiate the type

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, all! I am trying to write thist method for my project and on line 10 i get the following error : "Cannot instantiate the type Speaker"
Can anybody help me with this?



 
Bartender
Posts: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is Speaker?
It looks like it is an interface or an abstract class.
If it is, you cannot instantiate it. You should instantiate a class extending Speaker or an implementation of Speaker interface instead.

A hint: your method would be better if it declared it returns List<Speaker> instead of ArrayList<Speaker>.
If you even feel a need to use different implementation of list, you would be free to do so without braking or changing your (or other people's) code.
 
Greenhorn
Posts: 7
Firefox Browser Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You cannot create an object of "Speaker". Is it an interface? Is it an abstract class? Is the class's constructor private? Does it require use of a singleton to get ahold of? Does it consist of only static use methods?
 
reply
    Bookmark Topic Watch Topic
  • New Topic