Eclipse keeps giving me the error:
The value for annotation attribute Min.value must be a constant expression
But I am most definitely giving the annotation a constant.
private static final int MIN_YEAR = Calendar.getInstance().get(Calendar.YEAR) - 1;
@Min(MIN_YEAR)
If I change it to be
private static final int MIN_YEAR = 2013;
It's perfectly happy, but I shouldn't have to do that. Does anyone know why or how my MIN_YEAR constant isn't considered a constant if it's declared with an evaluated expression instead of a plain number?
The expression
private static final int MIN_YEAR = Calendar.getInstance().get(Calendar.YEAR) - 1;
will be determined only in run-time, but
private static final int MIN_YEAR = 2013;
is determined in compilation time, so it's allowed since the values in the annotations should be resolved at compilation time and not runtime.
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