A variable that is declared as final and not initialized is called a blank final variable. A blank final variable forces the constructors to initialize it.
In other words
The final property of class must have a value assigned before object is created. So the last point where you can assign value to them is constructor.
This is used often for immutable objects.
public class Foo {
private final Bar bar;
public Foo(Bar bar) {
this.bar = bar;
}
public Bar getBar() {
return new Bar(bar);
}
}



Leave a Reply