View Javadoc
1   /*xml
2   <module name="Checker">
3     <module name="TreeWalker">
4       <module name="FinalLocalVariable">
5         <property name="tokens" value="VARIABLE_DEF"/>
6         <property name="validateEnhancedForLoopVariable" value="true"/>
7       </module>
8     </module>
9   </module>
10  */
11  
12  
13  
14  package com.puppycrawl.tools.checkstyle.checks.coding.finallocalvariable;
15  
16  // xdoc section -- start
17  class Example3
18  {
19    static int foo(int x, int y) {
20      //ok, because PARAMETER_DEF is not configured in tokens
21      return x+y;
22    }
23    public static void main (String []args) {
24      // ok above, because PARAMETER_DEF is not configured in tokens
25      // violation below, 'Variable 'i' should be declared final'
26      for (String i : args) {
27        System.out.println(i);
28      }
29      int result=foo(1,2); // violation, 'Variable 'result' should be declared final'
30    }
31  }
32  // xdoc section -- end