• Post Reply Bookmark Topic Watch Topic
  • New Topic

Regarding local variable initialization  RSS feed

 
Gunjan Kumar
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have one doubt : Following text is from Java Specs 3.0

While all other variables are automatically initialized to a default value, the Java programming language does not automatically
initialize local variables in order to avoid masking programming errors.

What does this masking programming errors mean ? Please explain me with one example
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think they mean that using the default value for a local variable might lead to a bug, so the compiler reminds you to always initialize to some specific value. I don't know why they didn't apply the same logic to member variables.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!