Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javafx like Callback but without return

Tags:

java

javafx

I'm looking for a standard Javafx or java interface (if it exists) that acts like a Callback, except that it does not return a value.

The standard Callback from javafx.util package is as follows:

public interface Callback<P,R> {
    public R call(P param);
}

This is useful when you need to return the value, but I don't. I've looked into Callable<T>:

public interface Callable<V> {
    V call() throws Exception;
}

But this doesn't actually pass in a value into call. What I'm looking for is basically this:

public interface Callable<V> {
    void call(V value) throws Exception;
}

Is there a standard Java interface, or should I just create my own?

like image 253
user2914191 Avatar asked Oct 14 '17 15:10

user2914191


1 Answers

What are you looking for is Consumer. That's added since java 8.

Represents an operation that accepts a single input argument and returns no result. Unlike most other functional interfaces, Consumer is expected to operate via side-effects.

@FunctionalInterface
public interface Consumer<T> {

/**
 * Performs this operation on the given argument.
 *
 * @param t the input argument
 */
void accept(T t);
like image 191
Schidu Luca Avatar answered Oct 03 '22 08:10

Schidu Luca