Don't forget function pointers:
Java Code:
package lambdas;import java.util.*;import java.util.function.*;/**
*
* @author Brandon
*/public class Lambdas
{ /**
* @param args the command line arguments
*/ public static void main
(String[] args
) { Thread t
= new Thread(() -> { System.
out.
println("Thread Proc"); }); t.
start(); sleep
(100); Thread t2
= new Thread(() -> System.
out.
println("Thread Proc 2")); t2.
start(); sleep
(100); Thread t3
= new Thread(Lambdas
::somefunc
); t3.
start(); sleep
(100); Thread t4
= new Thread((new Lambdas
())::somefunc2
); t4.
start(); sleep
(100); List
<Integer
> list
= Arrays.
asList(10,
3,
9,
6,
4,
1,
7,
8,
5,
2); sort
(list,
(Integer a,
Integer b
) -> a
< b
); list.
forEach(System.
out::println
); System.
out.
println(); System.
out.
println(); list
= Arrays.
asList(10,
3,
9,
6,
4,
1,
7,
8,
5,
2); list.
sort((a, b
) -> a
< b
? a.
equals(b
) ? 0 : -1 : 1); list.
forEach(System.
out::println
); } static void somefunc
() { System.
out.
println("Some func"); } void somefunc2
() { System.
out.
println("Some func 2"); } static <T
> void sort
(List
<T
> list, BiFunction
<T, T, Boolean
> func
) { for (int i
= 0; i
< list.
size() - 1; ++i
) { for (int j
= 0; j
< list.
size() - i
- 1; ++j
) { T a
= list.
get(j
); T b
= list.
get(j
+ 1); if (func.
apply(b, a
)) { T temp
= a
; list.
set(j, b
); list.
set(j
+ 1, temp
); } } } } static void sleep
(long millis
) { try { Thread.
sleep(1000); } catch (InterruptedException e
) { } }}
In PS, the equivalent of any of the above would be:
Simba Code:
procedure somefunc();
begin
writeln('Some func');
end;
procedure somefunc2();
begin
writeln('Some func 2');
end;
procedure sort(var list: array of Integer; func: Function(A, B: Integer): Boolean);
var
I, J, L: Integer;
a, b, temp: Integer;
begin
L := Length(list);
for I := 0 To L - 1 do
begin
for J := 0 to L - I - 2 do
begin
a := list[j];
b := list[j + 1];
if (func(b, a)) then
begin
temp := a;
list[j] := b;
list[j + 1] := temp;
end;
end;
end;
end;
procedure SleepEx(millis: LongInt);
begin
try
sleep(millis);
except
end;
end;
function compare(a, b: Integer): boolean;
begin
Result := a < b;
end;
var
list: array of Integer;
begin
list := [10, 3, 9, 6, 4, 1, 7, 8, 5, 2];
Sort(list, @compare);
writeln(list);
end.