Random example: In the source code of one of my programs I have this method:
public @NotNull Currency[] getCurrencies() {
return this.currencies.values().toArray(new Currency[0]);
}
Which, after being compiled, gets turned into the following by my IDE (Intellij):
@NotNull
public Currency[] getCurrencies() {
Currency[] var10000 = (Currency[])this.currencies.values().toArray(new Currency[0]);
if (var10000 == null) {
$$$reportNull$$$0(4);
}
return var10000;
}
this.currencies
refers to private final ConcurrentHashMap<String, Currency> currencies = new ConcurrentHashMap();
- which means that only via means of reflection or cosmic rays causing bit flips, the method getCurrencies()
could ever return null
.
- Should I - in such cases where there is no chance for a
null
being returned - forgo the usage of the@NotNull
annotation? - Does the annotation even have significant impact on performance, or do the benefits of having the annotation outweigh the performance impact?
Thank you
/edit:
I am using the annotation package org.jetbrains.annotations