java - PMD violation on for each loop (final or not?) -
i found out pmd , want improve code it. therefore have enabled rules (and got 47000 violations :p). anyway, have problem one:
double mean = 0; (int p : points) mean += full[1][p]; mean /= points.size(); on for each loop, pmd tells me local variable 'p' declared final. if change to
double mean = 0; (final int p : points) mean += full[1][p]; mean /= points.size(); it tells me avoid using final local variables, turn them fields. second violation doesn't make sense me. "correct" way this? (i realize there may different ways, want know how pmd be.)
i think found inconsistency in pmd's rules, when following 1 of rules makes violate rule.
i think first loop fine is: second loop works fine, too, using final there rather unorthodox. adding final there without cause+ trip experienced developers. since not want make reading program harder is, i'd recommend skipping final in foreach loops.
+ making loop variable available anonymous class 1 such cause.
Comments
Post a Comment