I want to initialize a constant variable, which is'final', but I also want to include it in the constructor of a class but I do not know if that's fine:
public class Avion
{
private final BigDecimal limiteAltura;
public Avion(String limiteAltura)
{
this.limiteAltura = new BigDecimal(limiteAltura);
}
}
It is not assumed that the constructor initializes a field with suitable values, well I initialize it with a String that by default will be null
, or so I believe, but I get the impression that it can be done in another way. Also a constant has to be initialized at the time of its declaration or in the constructor so I do not know how to link all of this. What I want to achieve is to be explicit not to forget code.