我正在寻找一个标准Javafx或java接口(如果存在),该接口的作用类似于Callback
,但它不会返回任何值。
该标准Callback
从javafx.util
包装如下:
public interface Callback<P,R> {
public R call(P param);
}
Run Code Online (Sandbox Code Playgroud)
当您需要返回值时,这很有用,但我不需要。我调查了Callable<T>
:
public interface Callable<V> {
V call() throws Exception;
}
Run Code Online (Sandbox Code Playgroud)
但这实际上并没有将值传递给call
。我要找的基本上是这样的:
public interface Callable<V> {
void call(V value) throws Exception;
}
Run Code Online (Sandbox Code Playgroud)
是否有标准的Java接口,还是应该只创建自己的接口?
你在找什么Consumer
。自以来已添加java 8
。
表示一个接受单个输入参数且不返回结果的操作。与大多数其他功能接口不同,消费者应该通过副作用来操作。
@FunctionalInterface
public interface Consumer<T> {
/**
* Performs this operation on the given argument.
*
* @param t the input argument
*/
void accept(T t);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
214 次 |
最近记录: |