File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes initializing thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "initializing thread" Watch "initializing thread" New topic

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 will generate
compilation error("variable t might not have been initialized")
is there is any problem in this

"I Love Java Ranch"
Rob Spoor

Joined: Oct 27, 2005
Posts: 20269

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.

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'.”
I agree. Here's the link:
subject: initializing thread
It's not a secret anymore!