• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

INterface should have implemetation

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


here ExecutorService is an interface and Executors.newFixedThreadPool(NTHREDS); return a n intreface ,how it is possible?,an interface should have implementation class ?
 
Ranch Hand
Posts: 180
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sanjey,

Here actually the type of reference is an interface but it is actually
poniting to an implementation of ExecutorService.

The method Executors.newFixedThreadPool(NTHREDS); actually
returns an implementation of ExecutorService.

cheers,
Saurav
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's perfectly ok to make a variable of a type that is an interface refer to an object of a class that implements the interface. For example, you can write:

Note that List is an interface, and ArrayList is a class that implements the List interface. The rest of the program, that uses list, only needs to know that it is an object of a class that implements List; it doesn't need to know that it's actually an ArrayList (or some other implementation such as LinkedList).

Likewise, the method Executors.newFixedThreadPool returns an object that's an instance of a class that implements the ExecutorService interface. You don't need to know what that exact class is to be able to use the ExecutorService.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic