1 package com.puppycrawl.tools.checkstyle.checks.coding.requirethis;
2
3 import java.util.function.Consumer;
4 public class InputRequireThisAllowLambdaParameters {
5 private String s1 = "foo1";
6 int x=-1;
7 int y=-2;
8
9 void foo1() {
10 final java.util.List<String> strings = new java.util.ArrayList<>();
11 strings.add("foo1");
12 strings.stream().filter(s1 -> s1.contains("f"))
13 .collect(java.util.stream.Collectors.toList());
14
15 s1 = "foo1";
16 }
17
18 void foo2() {
19 final java.util.List<String> strings = new java.util.ArrayList<>();
20 strings.add("foo1");
21 strings.stream().filter(s1 -> s1.contains(s1 = s1 + "2"))
22 .collect(java.util.stream.Collectors.toList());
23 }
24
25 class FirstLevel {
26
27 int x;
28 int y;
29 int z;
30 void methodInFirstLevel(int x) {
31 Consumer<Integer> myConsumer = (y) ->
32 {
33 new String("x = " + x);
34 new String("y = " + y);
35 new String("InputRequireThisAllowLambdaParameters.this.x = " +
36 InputRequireThisAllowLambdaParameters.this.x);
37 y=x+z++;
38 };
39 myConsumer.accept(x);
40 }
41 }
42 }
43
44 class Calculator {
45
46 int a;
47 int b;
48 interface IntegerMath {
49 int operation(int a, int b);
50 }
51
52 public int operateBinary(int a, int b, IntegerMath op) {
53 return op.operation(a, b);
54 }
55
56 public void addSub(String... args) {
57
58 Calculator myApp = new Calculator();
59 IntegerMath addition = (a, b) -> a = a + b;
60 IntegerMath subtraction = (a, b) -> a = a - b;
61 myApp.operateBinary(20, 10, subtraction);
62 myApp.operateBinary(a++, b, addition);
63 }
64 }