Skip to content
Advertisement

Javafx like Callback but without return

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:

JavaScript

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

JavaScript

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

JavaScript

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

Advertisement

Answer

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.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement