Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is this correct ?

 
jose chiramal
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read this on the net.
You can start a thread "inline" without implementing Runnable or extending Thread class

( new Thread() { public void run()
{
// do something
} } ).start();

This actually is extending the Thread class. Then in that case what is an inline thread ?
 
Jim Hoglund
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are correct. What you have shown is what you read about.
It is the "in-line" version, or one line of code...

Jim ... ...
 
Campbell Ritchie
Sheriff
Posts: 48921
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That looks to me like an instance of an anonymous inner class.
 
Elchin Asgarli
Ranch Hand
Posts: 222
Chrome Eclipse IDE Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is correct, but its extremely ugly, so never do it at the job
 
getshijos joseph
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes this is correct ...but not a best practice

javarecharge.com
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:That looks to me like an instance of an anonymous inner class.

definitely! (I think so)
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jose chiramal wrote:I read this on the net.
You can start a thread "inline" without implementing Runnable or extending Thread class

( new Thread() { public void run()
{
// do something
} } ).start();

This actually is extending the Thread class. Then in that case what is an inline thread ?


this is currrect..we can do this because here we are creating a thread class instance using new.
and thread class itself implementing a runnable interface remember it is overriding public void run() method.

So it is surely possibly.........
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic