jasy blogja

The tricky Java compiler 2.

jasy képe

The variable might not have been initialized

Each local variable and every blank final field must have a definitely assigned value when any access of its value occurs.
For this purpose the standard introduced the concepts of definitely assigned and definitely unassigned variables.
If a variable is definitely unassigned when it is used, a compiler error occurs.

In our following example the compiler says that the variable o might not have been initialized in the statement "if (o.equals(args))".

The tricky Java compiler

jasy képe

I think many of us have met the situation while compiling Java sources that the code was not compileable, although its small modification, which had the same semantic, provided a compileable code. This is annoying, especially when we want to carry out some automatic refactorings on our code.

Tartalom átvétel