What does the Type parameter for Thread and Runnable signify?

200 Views Asked by At

Look at the following code from the ThreadFactory interface

 public Thread<T> newThread(Runnable<T> runnable);

What does s the type parameter convey here ? I mean Collection makes sense since T is specifying the type of objects that can go into the Collection but what does Runnable or Thread mean ?

3

There are 3 best solutions below

0
Peter Lawrey On BEST ANSWER

In ThreadFactory.newThread(Runnable) there is no generic type, nor is Runnable or Thread a generic interface/class. The original must have been in error.

2
Tirtha On

Thread class you are creating,it has to be the subclass of some other class, it can’t extend from the Thread class. This is because Java does not allow a class to inherit from more than one class. That's why Runnable interface to implement threads.

For better understanding,just take a look of these two links this1 and this2

2
John Kane On

It does not look like Runnable this was intended with the Runnable interface. Maybe you are getting confused with Callable. Here the generic type will be the type returned.