8

How this is possible? How am I able to change variables marked as final?

public class Main
{
    public static void main(String[] args)
    {
        final int NUM;

        NUM = 22;
        NUM = 33;

        System.out.println(NUM);
    }

}

I was using AIDE app in Android... it compiled successfully and printed 33.

k_ssb
  • 6,024
  • 23
  • 47

1 Answers1

4

If you can do this, it is a bug in the AIDE app. You should report it to the developers. A JLS compliant implementation of Java does not allow reassignment of final variables (like this).

If you want to give them a JLS specification reference to support your bug report:

JLS 4.12.4 final variables

A variable can be declared final. A final variable may only be assigned to once. It is a compile-time error if a final variable is assigned to unless it is definitely unassigned immediately prior to the assignment (§16 (Definite Assignment)).

Community
  • 1
  • 1
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216