Java 8 functional interface with no arguments and no return value

What is the Java 8 functional interface for a method that accepts nothing and returns nothing?

Ie, equivalent to C # without Action parameters with void return type?

+58
java java-8 java-stream
May 26 '14 at 11:08
source share
2 answers

If I understand correctly, you need a functional interface with the void m() method. In this case, you can just use Runnable .

+55
May 26 '14 at 11:22
source share

Just create your own

 @FunctionalInterface public interface Procedure { void run(); default Procedure andThen(Procedure after){ return () -> { this.run(); after.run(); }; } default Procedure compose(Procedure before){ return () -> { before.run(); this.run(); }; } } 

and use it like this:

 public static void main(String[] args){ Procedure procedure1 = () -> System.out.print("Hello"); Procedure procedure2 = () -> System.out.print("World"); procedure1.andThen(procedure2).run(); System.out.println(); procedure1.compose(procedure2).run(); } 

and exit

 HelloWorld WorldHello 
0
Jul 31 '17 at 15:07
source share



All Articles