Why does javac complain about not initialized variable?

Posted by Marcus on Stack Overflow See other posts from Stack Overflow or by Marcus
Published on 2010-02-02T20:55:09Z Indexed on 2010/06/10 20:12 UTC
Read the original article Hit count: 269

Filed under:
|

For this Java code:

String var;
clazz.doSomething(var);

Why does the compiler report this error:

Variable 'var' might not have been initialized

I thought all variables or references were initialized to null. Why do you need to do:

String var = null;

??

© Stack Overflow or respective owner

Related posts about java

Related posts about initialization