[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.tools.jdt] Re: Error when final fields (constants) not initialized at declaration

"Geri Broser" <gerold.broser@xxxxxxxxxxxxx> wrote in message 
news:fbmh1a$1fe$1@xxxxxxxxxxxxxxxxxxxx
> Java allows the following (at least till v1.4), but JDT marks both lines 
> with errors, without the possibility to suppress it in Preferences -> 
> Java -> Compiler -> Errors/Warnings:
>
> MyClass
>   {
>   private final String MY_CONSTANT; // msg: "The empty final field 
> MY_CONSTANT is possibly not initialized"
>
>   MyClass()
>     {
>     MY_CONSTANT = "MyValue"; // msg: "The final field MyClass.MY_CONSTANT 
> cannot be assigned"
>     }
>   }


If I add the keyword "class" before the first "MyClass", that code compiles 
with no errors for me in Eclipse.

Have you tried this in a project with default compiler settings?  What are 
your compiler settings?  What version of Eclipse are you using?