Java 8 lambda Void argument
I think this table is short and usefull:
Supplier () -> xConsumer x -> ()Callable () -> x throws exRunnable () -> ()Function x -> yBiFunction x,y -> zPredicate x -> booleanUnaryOperator x1 -> x2BinaryOperator x1,x2 -> x3
As said on the other answers, the appropriate option for this problem is a Runnable
The syntax you're after is possible with a little helper function that converts a Runnable
into Action<Void, Void>
(you can place it in Action
for example):
public static Action<Void, Void> action(Runnable runnable) { return (v) -> { runnable.run(); return null; };}// Somewhere else in your code Action<Void, Void> action = action(() -> System.out.println("foo"));