Variable initialized but javac presents compilation error

Felipe Barros Pontes felipepontes at
Tue Jun 7 13:48:43 UTC 2016

Hi all.

   The Java Language Specification 8 presents in section
(final Fields) the following note: "A blank final instance variable
must be definitely assigned at the end of every constructor of the
class in which it is declared, or a compile-time error occurs..."

   In the following program the variable "x" is initialized at the end
of the constructor but javac presents a compilation error.


	class A {
		final int x;
		A() {
		void setX() {
			this.x = 10;

Result error: cannot assign a value to final variable x
			this.x = 10;
1 error

   Shouldn't it be compiled successfully?

Best regards,

Felipe Pontes
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the compiler-dev mailing list