不带任何内容且不返回任何内容的功能接口

2022-08-31 07:03:52

JDK 中是否有不带任何内容且不返回任何内容的标准功能接口?我找不到一个。如下所示:

@FunctionalInterface
interface Action {
  void execute();
}

答案 1

运行怎么样 :

@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();
}

答案 2