I wanted to break the constructor of my class into parts. But I have a problem ...
Is it possible to initialize the final value in a method called inside the constructor? Should it be initialized directly in the constructor?
It...
import java.util.Scanner;
public final class A
{
private final int L;
private final int D;
private final int N;
public A()
{
Scanner scanner = new Scanner(System.in);
this.getFirstLine(scanner);
}
private void getFirstLine(Scanner scanner)
{
this.L = scanner.nextInt();
this.D = scanner.nextInt();
this.N = scanner.nextInt();
}
}
gives me errors similar to The final field A.L cannot be assigned.
So, is this considered an appointment? Yes?
Is there a way to split the constructor to achieve what I wanted?
Thanks in advance.
source
share