-1

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 ?

Inquisitive
  • 7,476
  • 14
  • 50
  • 61
  • 7
    Where did you see that code? It says [`Thread newThread(Runnable r)`](http://docs.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/ThreadFactory.html#newThread(java.lang.Runnable)). – Marko Topolnik Jul 10 '12 at 12:15
  • @MarkoTopolnik first answer in http://stackoverflow.com/questions/5762991/how-does-java-util-concurrent-executor-work/5766067 – Inquisitive Jul 10 '12 at 12:18
  • 2
    @MarkoTopolnik, bring it on! the owl is up all night ;) – TeaCupApp Jul 10 '12 at 12:19
  • @Subhra If you actually look up the ThreadFactory code from Oracle, not once does it mention templatisation. – Nathan White Jul 10 '12 at 12:19
  • 1
    Subhra, that guy was obviously typing from memory. As you say it's meaningless and indeed it is not real. – Marko Topolnik Jul 10 '12 at 12:23
  • @nathanwhite please see the source of that code in the link I gave in another comment above – Inquisitive Jul 10 '12 at 12:23
  • @Subhra I did, but then the first person to get it wrong simply influenced a second person to get it wrong. If it's not on Oracles website as that, it isn't the case. – Nathan White Jul 10 '12 at 12:26

3 Answers3

4

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.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
0

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

Community
  • 1
  • 1
Tirtha
  • 351
  • 2
  • 6
  • 22
0

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.

John Kane
  • 4,383
  • 1
  • 24
  • 42