I have been reading some open source libraries which use the following code:
//noinspection ForLoopReplaceableByForEach
for (int i = 0, count = list.size(); i < count; i++) {
// do something
}
What does //noinspection ForLoopReplaceableByForEach
mean?
//noinspection
is an IntelliJ specific annotation. It's similar to Java's @SupressWarnings
except that it can be used for a single statement instead of declaring it at class or method level as @SupressWarnings
.
In this case, it is suppressing the warning that the For loop could be replaced by a ForEach.
It means that you're using a counter to run through the list, when you could just do:
for (Object obj : list)
where Object is replaced by the type of the Object in list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With