Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does //noinspection ForLoopReplaceableByForEach mean?

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?

like image 256
Macarse Avatar asked Jul 24 '13 14:07

Macarse


2 Answers

//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.

like image 194
Daniel Avatar answered Oct 12 '22 18:10

Daniel


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.

like image 42
Choker Avatar answered Oct 12 '22 17:10

Choker