API / Apache Velocity Interview questions
What is silent/quiet reference notation ($!) used for?
Prefixing a reference with $! instead of $ suppresses the fallback literal output when the reference is undefined or null. With a plain $middleName, an unset variable prints as the literal text $middleName; with $!middleName, it prints as an empty string instead.
Name: $user.firstName $!user.middleName $user.lastName
This is the standard way to handle genuinely optional fields in a template without needing an #if check for every one of them. It also works with the formal notation, as $!{middleName}, when trailing text would otherwise merge into the variable name.
More Related questions...