File: Util.java

package info (click to toggle)
eclipse-jdt-ui 4.29-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 93,280 kB
  • sloc: java: 831,977; xml: 14,578; jsp: 33; makefile: 5
file content (107 lines) | stat: -rw-r--r-- 2,204 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package p;

interface SAM1 {
	X apply(X x1);
}

interface SAM2 {
	X apply(X x1);
}

interface SAM3 {
	X apply(X x1);
}

interface SAM4 {
	X apply(X x1);
}

interface SAM5 {
	X apply(X x1);
}

interface SAM6 {
	X apply(X x1);
}

interface SAM7 {
	X apply(X x1);
}

class Base {
	X method1(X x) {
		return new X("created in Base::method1");
	}

	X method2(X x) {
		return new X("created in Base::method2");
	}

	X method3(X x2) {
		return x2;
	}
}

public class Util extends Base {
	X method1(X x) {
		return new X("created in method1");
	}

	X method2(X x) {
		return new X("created in method2");
	}

	String static_method(X x1) {
		SAM1 sam1 = X::staticMethod;
		return sam1.apply(x1).m2();
	}

	String instance_method_via_type(X x2) {
		SAM2 sam2 = p.X::instanceMethod;
		return sam2.apply(x2).m2();
	}

	String constructor_ref(X x3) {
		SAM3 sam3 = X::new;
		return sam3.apply(x3).m2();
	}

	String this_method1(X x4) {
		SAM4 sam4 = this::method1;
		return sam4.apply(x4).m2();
	}

	String super_method2(X x5) {
		SAM5 sam5 = super::method2;
		return sam5.apply(x5).m2();
	}

	String instance_method2(X x6) {
		SAM6 sam6 = x6::instanceMethod2;
		return sam6.apply(x6).m2();
	}

	String instance_method2_via_field(X x7) {
		SAM7 sam7 = x7.field::instanceMethod2;
		return sam7.apply(x7).m2();
	}

	public static void check(String expected, String actual) {
		if (!expected.equals(actual)) {
			System.out.println(expected + " != " + actual);
		} else {
			System.out.println("OK: " + expected);
		}
	}

	public static void main(String[] args) {
		Util util = new Util();
		check("created in X::staticMethod", util.static_method(new X("static_method")));
		check("created in X::instanceMethod", util.instance_method_via_type(new X("instance_method_via_type")));
		check("created in X::new", util.constructor_ref(new X("constructor_ref")));
		check("created in method1", util.this_method1(new X("this_method1")));
		check("created in Base::method2", util.super_method2(new X("super_method2")));
		check("created in X::instanceMethod2", util.instance_method2(new X("instance_method2")));
		check("created in X::instanceMethod2", util.instance_method2_via_field(new X("instance_method2_via_field")));
	}
}