| Author |
initializing thread
|
saravanan ragunathan
Ranch Hand
Joined: Aug 02, 2010
Posts: 84
|
|
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
|
"I Love Java Ranch"
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
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.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
K Abhijit
Ranch Hand
Joined: Mar 03, 2008
Posts: 88
|
|
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
|
“The difference between 'involvement' and 'commitment' is like an eggs-and-ham breakfast: the chicken was 'involved' - the pig was 'committed'.”
|
 |
 |
|
|
subject: initializing thread
|
|
|