NEW in Lombok 0.10: You can use val
as the type of a local variable declaration instead of actually writing the type. When you do this,
the type will be inferred from the initializer expression. The local variable will also be made final. This feature works
on local variables and on foreach loops only, not on fields. The initializer expression is required.
WARNING: This feature does not currently work in NetBeans. We're working on fixing that.
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.