DEV Community

Discussion on: How to write a callback function in Java

Collapse
mategreen profile image
matej

Hi, you can also use java interface Supplier for the same purpose. Something like this:

Supplier<String> supplier = () -> "one";
System.out.println(supplier.get());

or in method

System.out.println(myMeth(() -> "one"));
...
String myMeth(Supplier<String> s) {
   return s.get();
}
Collapse
kdfemi profile image
MiniSoda Author

Whoa! Never knew this existed. Will try implementing this