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
.
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
variablesA 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)).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With