final and immutability are two orthogonal concepts:
val means that you cannot change (mutate) a variable by assigning it anything after the initial declaration:
val x = 1
x = 2 // error: reassignment to val
In the JVM bytecode, it is implemented by creating a private member and getter, but not setter:
class A {
val x = 1
}
=>
public class A {
private final int x;
public int x() { return x; }
...
}
finalmeans you cannot override valin a subclass:
class A {
final val x = 1
}
class B extends A {
override val x = 2
}
final , var val.