@var

Since

@var was introduced as experimental feature in lombok v1.16.11.

Experimental

Experimental because:

  • This feature is very controversial.
  • There is JEP 286 that should make the @var obsolete.
Current status: uncertain - Currently we feel this feature cannot move out of experimental status.

Overview

The @var has the same mission as the @val annotation but modifable.

With Lombok

@HTML_PRE@

Vanilla Java

@HTML_POST@

Supported configuration keys:

lombok.val.flagUsage = [allow] (default: not set)
Lombok will flag any usage of var as a error if not configured.

Small print

For compound types, the most common superclass is inferred, not any shared interfaces. For example, bool ? new HashSet() : new ArrayList() is an expression with a compound type: The result is both AbstractCollection as well as Serializable. The type inferred will be AbstractCollection, as that is a class, whereas Serializable is an interface.

In ambiguous cases, such as when the initializer expression is null, java.lang.Object is inferred.