4 ms·
I'll give a shot at the last one: Future is something that will eventually produce a value. CompletableFuture is a Future that you can register a callback on
by orclev 7y ago
I'll give a shot at the last one:
Future is something that will eventually produce a value.
CompletableFuture is a Future that you can register a callback on for when it completes.
RunnableFuture I'm not completely sure on, but I'd guess it's a Future that will complete but won't produce a value (basically a Future<Void>).
ScheduledFuture is a Future that you can specify when it should run in the future.
ScheduleRunnableFuture is a RunnableFuture that has a defined time it should start running.
FutureTask is a RunnableFuture you can cancel. OK, so I cheated on this one, I didn't actually know what it was and had to look it up.
Edit: I looked up RunnableFuture and I was half right. It's something that's both a Runnable and a Future, so it has a run() method that causes the future to be evaluated but doesn't return its result at that time. It actually seems pretty niche and probably only useful if you already have some API that's expecting a Runnable, otherwise it's exactly equivalent to calling get() on a Future then ignoring the returned value.
- lostcolony 7y agoCool; next question - you have a library that returns Futures. You have another library that takes CompletableFutures. How do you feed the output of the first into the input of the second? Also, as a note, FutureTask is the only implemented class out of those; the others are all interfaces.