@Target(value={FIELD,PARAMETER,LOCAL_VARIABLE}) @Retention(value=RUNTIME) @IncompatibleModifiers(value=FINAL) public @interface Var
Most references are never modified, and accidentally modifying a reference is a potential source of bugs. To prevent accidental modifications, the accompanying Error Prone check prevents parameters and local variables from being modified unless they are explicitly annotated with @Var.
Since Java 8 can infer whether a local variable or parameter is effectively final
, and
@Var
makes it clear whether any variable is non- final
, explicitly marking local
variables and parameters as final
is discouraged.
The annotation can also be applied to fields, to indicate that the field is deliberately non-final.
Copyright © 2021. All rights reserved.