forked from hellokaton/write-readable-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample2.java
More file actions
52 lines (44 loc) · 1.26 KB
/
Copy pathExample2.java
File metadata and controls
52 lines (44 loc) · 1.26 KB
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
package chapter_03;
import java.io.IOException;
import java.nio.file.Files;
import java.util.function.Function;
/**
* 避免tmp和retval这样泛泛的名字
*
* @author biezhi
* @date 2018/6/24
*/
public class Example2 {
public void before() {
// Function<int[], Double> euclideanNorm = v -> {
// double retval = 0;
// for (int i = 0; i < v.length; i++)
// retval += v[i] * v[i];
// return Math.sqrt(retval);
// };
//
// int[] numbs = {1, 2, 3, 5};
// Double apply = euclideanNorm.apply(numbs);
// System.out.println(apply);
}
public void after() {
Function<int[], Double> euclideanNorm = v -> {
double sumSquares = 0;
for (int i = 0; i < v.length; i++)
sumSquares += v[i] * v[i];
return Math.sqrt(sumSquares);
};
int[] numbs = {1, 2, 3, 5};
Double apply = euclideanNorm.apply(numbs);
System.out.println(apply);
}
public void numberSwap(int right, int left){
int tmp = right;
right = left;
left = tmp;
}
public void tempUser() throws IOException {
// String tmp = user.getUserName();
Files.createTempFile("tmp_file", ".txt");
}
}