Non-compile-time constant expression passed to parameter with @CompileTimeConstant type annotation.


The problem

A method or constructor with one or more parameters whose declaration is annotated with the @CompileTimeConstant type annotation must only be invoked with corresponding actual parameters that are computed as compile-time constant expressions, specifically expressions that:

For example, the following are valid compile-time constants:

When applied to fields, this check enforces that the field is final and has an initializer which satisfies the above conditions.

Getting Java 8 references to methods with @CompileTimeConstant parameters is disallowed because we couldn’t check if the method reference is later applied to a compile-time constant. Use the methods directly instead.

For the same reason, it’s also disallowed to create lambda expressions with @CompileTimeConstant parameters.


Suppress false positives by adding the suppression annotation @SuppressWarnings("CompileTimeConstant") to the enclosing element.