aspose file tools
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 Groovy Fundamentals video training course this week in the Groovy forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "default initialization" Watch "default initialization" New topic

default initialization

Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347

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?

Visit my download page
Darryl Burke

Joined: May 03, 2008
Posts: 4910

That's something the language designers decided:

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

Joined: Oct 21, 2000
Posts: 4347

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:
subject: default initialization