While I understand what the final
keyword is used for in the context of classes and methods as well as the intent of its use for in regards to variables; however, the project I just started working on seems to have an excessive number of them and I'm curious as to the logic behind it.
The following snippet of code is just a short example as I don't see much point in the final
keyword for the key
and value
variables:
private <K, V> Collection<V> getValuesForKeys(
final Map<K, V> map, final Collection<K> keys)
{
final Collection<V> values = new ArrayList<V>(keys.size());
for (final K key : keys) {
final V value = map.get(key);
if (value != null) {
values.add(value);
}
}
return values;
}
I have been doing a bit of reading the usage through articles I have found via Google; however, does the pattern really do things such as help the compiler optimize the code?