Skip to content

Commit 7b1478a

Browse files
authored
Merge pull request #1 from mert-aydin/master
eliminated unnecessary object types
2 parents bd75c55 + e06e43c commit 7b1478a

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

FunctionPointerDemo.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import java.util.Arrays;
2+
13
interface FunctionWrapper {
24
int methodSignature(int n);
35
}
@@ -18,7 +20,6 @@ public static void main(String[] args) {
1820
FunctionWrapper functionPointer = FunctionPointerDemo::increment;
1921
myObjective(arr, functionPointer);
2022

21-
for (int elem : arr)
22-
System.out.print(elem + " ");
23+
System.out.println(Arrays.toString(arr));
2324
}
2425
}

FunctionPointerDemo2.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1+
import java.util.Arrays;
12
import java.util.function.Function;
23

34
public class FunctionPointerDemo2 {
4-
static Integer increment(Integer n) {
5+
static int increment(int n) {
56
return n + 1;
67
}
78

8-
static void myObjective(Integer[] arr, Function<Integer, Integer> f) {
9+
static void myObjective(int[] arr, Function<Integer, Integer> f) {
910
for (int i = 0; i < arr.length; ++i) {
1011
arr[i] = f.apply(arr[i]);
1112
}
1213
}
1314

1415
public static void main(String[] args) {
15-
Integer[] arr = {0, 1, 2, 3, 4};
16-
myObjective(arr, FunctionPointerDemo2::increment);
16+
int[] arr = {0, 1, 2, 3, 4};
17+
myObjective(arr, FunctionPointerDemo2::increment);
1718

18-
for (Integer elem : arr) {
19-
System.out.print(elem + " ");
20-
}
19+
System.out.println(Arrays.toString(arr));
2120
}
22-
}
21+
}

0 commit comments

Comments
 (0)