File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 19692
    
  20

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 - OCEEJBD 6
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: http://aspose.com/file-tools
 
subject: initializing thread