Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

initializing thread

 
saravanan ragunathan
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


the above code is executed successfully
but for experimental purpose when i write the below code
to start only the last thread i have created..it will generate
compilation error("variable t might not have been initialized")
is there is any problem in this



 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What will happen if you change that 10 into a 0? The compiler thinks in a similar way. It can't guarantee that t will have a value after the loop.
 
K Abhijit
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's Just a Compilation error: The local variable t may not have been initialized

unless any reference is target of assignment operator, compiler would not allow to use its L value..

simply assign null and then proceed


needless to say that there is a chance of NullPointer incase it bypasses for loop
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic