1
2
3
4
5
6
7
8
9 package com.puppycrawl.tools.checkstyle.checks.coding.finallocalvariable;
10
11 public class InputFinalLocalVariableEnhancedForLoopVariable {
12 public void method1()
13 {
14 final java.util.List<Object> list = new java.util.ArrayList<>();
15
16 for(Object a : list){
17 }
18 }
19
20 public void method2()
21 {
22 final int[] squares = {0, 1, 4, 9, 16, 25};
23 int x;
24 for (final int i : squares) {
25 }
26
27 }
28
29 public java.util.List<String> method3(java.util.List<String> snippets) {
30
31 java.util.List<String> filteredSnippets = new java.util.ArrayList<>();
32
33 for (String snippet : snippets) {
34 filteredSnippets.add(snippet);
35 }
36 if (filteredSnippets.size() == 0) {
37 String snippet = snippets.get(0);
38 snippet = new String(snippet);
39 filteredSnippets.add(snippet);
40 }
41 return filteredSnippets;
42 }
43
44 public void method4()
45 {
46 final java.util.List<Object> list = new java.util.ArrayList<>();
47
48 for(Object a : list) {
49 }
50
51 Object a;
52 if (list.isEmpty())
53 {
54 a = new String("empty");
55 }
56 else
57 {
58 a = new String("not empty");
59 }
60
61 for(Object b : list) {
62 b = new String("b");
63 }
64 }
65
66 }