Mutably! Hassle-free local variables.
varwas promoted to the main package in lombok 1.16.20; given that JEP 286 establishes expectations, and lombok's take on
varfollows these, we've decided to promote
vareventhough the feature remains controversial.
varwas introduced in lombok 1.16.12 as experimental feature.
var works exactly like
val, except the local variable is not marked as
The type is still entirely derived from the mandatory initializer expression, and any further assignments, while now legal (because the variable is no longer
final), aren't looked at to determine the appropriate type.
var x = "Hello"; x = Color.RED; does not work; the type of x will be inferred to be
java.lang.String and thus, the
x = Color.RED assignment will fail. If the type of
x was inferred to be
java.lang.Object this code would have compiled, but that's not how
Supported configuration keys:
error] (default: not set)
Lombok will flag any usage of
varas a warning or error if configured.