Differences
This shows you the differences between two versions of the page.
java_8_functions [2017/06/22 09:48] |
java_8_functions [2021/04/05 11:23] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Functions ====== | ||
+ | ===== Function with no Parameter and No Return Value ===== | ||
+ | |||
+ | You can just use the '' | ||
+ | |||
+ | Interface: | ||
+ | |||
+ | <sxh java> | ||
+ | void delete(int id, Runnable callback); | ||
+ | </ | ||
+ | |||
+ | Caller: | ||
+ | |||
+ | <sxh java> | ||
+ | delete(id, () -> { | ||
+ | // do some stuff like return data from a REST service | ||
+ | response.noContent().build(); | ||
+ | }); | ||
+ | </ | ||
+ | |||
+ | Callee: | ||
+ | |||
+ | <sxh java> | ||
+ | public void delete(int id, Runnable callback) { | ||
+ | getConnection(connection -> { | ||
+ | connection.delete(id, | ||
+ | if (result.success()) { | ||
+ | callback.run(); | ||
+ | } | ||
+ | else { | ||
+ | throw result.cause(); | ||
+ | } | ||
+ | }); | ||
+ | | ||
+ | }); | ||
+ | </ | ||
+ | |||
+ | {{tag> devel java}} |