1
2
3
4
5
6
7
8
9 package com.puppycrawl.tools.checkstyle.checks.coding.finallocalvariable;
10
11 public class InputFinalLocalVariableEnhancedForLoopVariable2 {
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 java.util.List<String> filteredSnippets = new java.util.ArrayList<>();
31 for (String snippet : snippets) {
32 filteredSnippets.add(snippet);
33 }
34 if (filteredSnippets.size() == 0) {
35 String snippet = snippets.get(0);
36 snippet = new String(snippet);
37 filteredSnippets.add(snippet);
38 }
39 return filteredSnippets;
40 }
41
42 public void method4()
43 {
44 final java.util.List<Object> list = new java.util.ArrayList<>();
45
46 for(Object a : list) {
47 }
48
49 Object a;
50 if (list.isEmpty())
51 {
52 a = new String("empty");
53 }
54 else
55 {
56 a = new String("not empty");
57 }
58
59 for(Object b : list) {
60 b = new String("b");
61 }
62 }
63
64 }