forked from lazerwalker/fuckingblocksyntax.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
140 lines (116 loc) · 3.06 KB
/
index.html
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<html>
<head>
<title>How Do I Declare A Lambda in Java?</title>
<style>
body {
background-color: #042029;
color: #83948F;
font-family: Lucida Grande, sans-serif;
font-size: 20px;
padding: 40px;
padding-bottom: 0;
}
strong {
color: #0088D9;
}
h1 {
font-size: 40px;
margin-bottom: 1.5em;
text-align: center;
}
h2 {
font-weight: normal;
}
.return {
color: #00A69A;
}
.name {
color: #BC8800;
}
.parameter-types, .parameters {
color: #7C9F00;
}
code {
display: block;
font-family: Monaco, Menlo;
font-size: 20px;
margin-bottom: 3em;
margin-left: 40px;
margin-top: 1.5em;
}
footer {
font-size: 12px;
margin-top: 200px;
opacity: 0.4;
text-align: right;
}
footer a {
color: #0088D9;
text-decoration: none;
}
</style>
<style media='print'>
body {
background-color: #FFFFFF;
font-size: 16px;
padding: 20px;
}
h1 {
font-size: 28px;
margin-bottom: 1em;
}
code {
font-size: 16px;
margin-bottom: 2em;
margin-left: 20px;
}
footer {
font-size: 10px;
margin-top: 40px;
}
</style>
</head>
<body>
<h1>How Do I Declare A Lambda in Java?</h1>
<div>
<h2>As an <strong>expression</strong> (example):</h2>
<code>
(Person <span class='parameters'>p</span>) -> <span class='parameters'>p</span>.getGender() == Person.Sex.MALE<br/>
  && <span class='parameters'>p</span>.getAge() >= 18<br/>
  && <span class='parameters'>p</span>.getAge() <= 25<br/>
</code>
</div>
<div>
<h2>As a <strong>local variable</strong>:</h2>
<code>
@FunctionalInterface<br/>
public interface SomeFunction {<br/>
  public <span class='return'>void</span> doWork();<br/>
}<br/>
<br/>
<span class='return'>SomeFunction</span> <span class='name'>lambdaName</span> = () -> {...};
</code>
</div>
<div>
<h2>As a <strong>method parameter</strong>:</h2>
<code>
@FunctionalInterface<br/>
public interface SomeFunction {<br/>
  public <span class='return'>void</span> doWork();<br/>
}<br/>
<br/>
void someMethodThatTakesALambda(<span class='return'>SomeFunction</span> <span class='name'>lambdaName</span>) {...}
</code>
</div>
<div>
<h2>As an <strong>argument to a method call</strong>:</h2>
<code>
someObject.someMethodThatTakesALambda ((<span class='return'>ParameterClass</span> <span class='parameters'>p</span>) -> {...});
</code>
</div>
<div><h3>This site doesn't cover every possible use of lambdas.
<footer>By <a href="http://florescu.org">Alex Florescu</a>, who likes Java and was impressed by the original <a href="http://fuckingblocksyntax.com/">Block syntax page</a>.<br/>
For bugs or suggestions, see github <a href="https://github.com/anothem/fuckingjavalambdasyntax.com">page</a>.
</footer>
</body>
</html>