The value of the Min.value annotation attribute must be a constant expression.

Eclipse keeps giving me an error:

The value for annotation attribute Min.value must be a constant expression 

But I definitely give the annotation constant.

 private static final int MIN_YEAR = Calendar.getInstance().get(Calendar.YEAR) - 1; @Min(MIN_YEAR) 

If I change it to

 private static final int MIN_YEAR = 2013; 

This is great, but I should not do it. Does anyone know why or how my constant MIN_YEAR is not considered a constant if it is declared with an evaluated expression instead of a prime number?

+4
source share
1 answer

Expression

 private static final int MIN_YEAR = Calendar.getInstance().get(Calendar.YEAR) - 1; 

will only be determined at runtime, but

 private static final int MIN_YEAR = 2013; 

is determined at compile time, so this is allowed, since the values ​​in the annotation should be allowed at compile time, not run time.

+9
source

Source: https://habr.com/ru/post/1482651/


All Articles