Interfaces Executor and ExecutorService
From my understanding, interfaces aren't concrete and hence can't be instantiated.
You must implement every method of an interface you implemet or declare the class an absract one.
My nightmare is with the Executor servuce interfcae used for multithrreading. I understand clearly that to excute a task concurrently, it must implemnt interface Runable, ( in the process override the run() method). And and object of type Executorservice must be create and method execute called on the runnable object.
An Executor service is and Executor being a sub interface of Executor so how and why does the compiler allow an object to be created from an interface? And
Why don't we over ride the execute() method of interface Executor since this an abstract one with no default implementation, aren't we supposed to provide implemetation details for this abstract method?
Re: Interfaces Executor and ExecutorService
There are a lot of big, fancy words to describe this, but none are coming immediate to mind and I don't want to google.
Basically, an object is not being created from an interface. The compiler simply assumes the runtime object type the method is being called upon (perhaps a Runnable type) has been initialized with some class which inherits from that type. That is a fair assumption, since the compiler will not explicitly let you initialize an interface or abstract class. So, at runtime, the object type can only be in one of the two states: legally initialized by some class which inherits from said type, or the object is null. If the object is null, a NullPointerException will be thrown at runtime, so that state is taken care of.