wood burning stoves 2.0*
The moose likes Java in General and the fly likes default initialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "default initialization" Watch "default initialization" New topic
Author

default initialization

Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

if i declare a variable but do not initialize it, java supplies a defaut. for reference variables it is assigned null.
ok, so why does the compiler complain that variable url might not be initialized?
i have to change it to
URL url = null;
is it because it is a local variable not a member variable?


SCJP
Visit my download page
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4531
    
    5

That's something the language designers decided: http://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.12.5


luck, db
There are no new questions, but there may be new answers.
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

there it is
A local variable (§14.4, §14.14) must be explicitly given a value before it is used, by either initialization (§14.4) or assignment (§15.26), in a way that can be verified using the rules for definite assignment (§16).

so, the answer is yes, it is because it is a local variable
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: default initialization