- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFunctionPointerDemo.java
More file actions
Latest commit
25 lines (19 loc) · 540 Bytes
/
Copy pathFunctionPointerDemo.java
File metadata and controls
25 lines (19 loc) · 540 Bytes
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
importjava.util.Arrays;
interfaceFunctionWrapper {
intmethodSignature(intn);
}
publicclassFunctionPointerDemo {
staticintincrement(intn) {
returnn + 1;
}
staticvoidmyObjective(int[] arr, FunctionWrapperf) {
for (inti = 0; i < arr.length; ++i)
arr[i] = f.methodSignature(arr[i]);
}
publicstaticvoidmain(String[] args) {
int[] arr = {0, 1, 2 ,3 ,4};
FunctionWrapperfunctionPointer = FunctionPointerDemo::increment;
myObjective(arr, functionPointer);
System.out.println(Arrays.toString(arr));
}
}