• Post Reply Bookmark Topic Watch Topic
  • New Topic

creating and starting threads : why is this illegal ?

 
Rahul Sudip Bose
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
new Thread().start(); is legal.
This starts a thread object without a reference. But why is : Thread t1 = new Thread().start(); illegal ?
Any explanations welcome.




 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you think the start() method returns? Because that's what you're assigning to t1.
 
Rahul Sudip Bose
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote:What do you think the start() method returns? Because that's what you're assigning to t1.


ok, got it...horrible mistake. Realized from sun docs that start() returns void.
now the error also makes sense.
code


error:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!