Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between passing object to constructor?

 
Rajiv Chopra
Ranch Hand
Posts: 62
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is technical difference if I pass Runnable in two different way. Please explain..

Thread thread = new Thread (new RunnableClass());

or

RunnableClass runnable = new RunnableClass();
Thread thread = new Thread(runnable);

Thanks in Advance...
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The difference is that you'll have another reference variable poiinting to the RunnableClass instance. Nothing else.
 
Salil Vverma
Ranch Hand
Posts: 255
Hibernate Oracle Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rajiv,

As mentioned by Sebastian, the difference is that you would have reference of runnable object in the second case. The second syntax is preferred when we want to create multiple threads on the same runnable instance.

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic