Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Function" with no args and no return type (void) in Java >= 8 [duplicate]

Is there a standard functional interface in the JDK that takes nothing and returns nothing? I cannot find one. Something like the following:

@FunctionalInterface
interface Action {
  void execute();
}
like image 762
deamon Avatar asked May 30 '14 16:05

deamon


People also ask

What is the lambda expression in Java 8?

Lambda Expressions were added in Java 8. A lambda expression is a short block of code which takes in parameters and returns a value. Lambda expressions are similar to methods, but they do not need a name and they can be implemented right in the body of a method.

How do you pass a function as a prop in Java?

If you want to pass a parameter to the function that you are passing as a prop, use an inline arrow function.To pass a function as props in React: Define the function in the parent component. Pass it as a prop to the child component, e.g. <Child handleClick={handleClick} /> . Use the function in the child component.


1 Answers

How about Runnable :

@FunctionalInterface
public interface Runnable {
    /**
     * When an object implementing interface <code>Runnable</code> is used
     * to create a thread, starting the thread causes the object's
     * <code>run</code> method to be called in that separately executing
     * thread.
     * <p>
     * The general contract of the method <code>run</code> is that it may
     * take any action whatsoever.
     *
     * @see     java.lang.Thread#run()
     */
    public abstract void run();
}
like image 118
Eran Avatar answered Oct 16 '22 16:10

Eran