I recently learned about PMD and want to improve my code. So I turned on all the rules (and got 47,000 violations: P). Anyway, I have a problem with this:
double mean = 0; for (int p : points) mean += full[1][p]; mean /= points.size();
In a for each loop, PMD tells me that the local variable 'p' can be declared final . If I change it to
double mean = 0; for (final int p : points) mean += full[1][p]; mean /= points.size();
he tells me Avoid using finite local variables, turn them into fields . The second violation does not make sense to me. What is the βrightβ way to do this? (I understand that there can be different ways, I just want to know how PMD will like it.)
source share