3 ms·
The scale of Java is also insane. The standard library is huge. The commonly leveraged frameworks, also huge. And the abstraction...my God, the unnecessary abst
by lostcolony 7y ago
The scale of Java is also insane. The standard library is huge. The commonly leveraged frameworks, also huge. And the abstraction...my God, the unnecessary abstraction.
How many people, offhand, know the difference between a Runnable, Callable, Function, Consumer, and Supplier? I include all of them because literally the only meaningful difference between them is whether they take an argument or not (Function and Consumer do), and whether they return an argument or not (Callable, Function, and Supplier do).
How many people know the difference between a Future, a CompletableFuture, a RunnableFuture, a ScheduledFuture, a ScheduledRunnableFuture, and a FutureTask? I've done async code in Java; I still can't keep them straight.
- orclev 7y agoI'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.