The title says it all, but what is the Java 8 equivalent of JavaScript's Promise.reject? I'm looking for a static method on CompletableFuture that will create a Future
in an exceptional state, but I don't see one.
Asked
Active
Viewed 217 times
1

battmanz
- 2,266
- 4
- 23
- 32
-
[`CompletableFuture.failedFuture`](https://docs.oracle.com/javase/10/docs/api/java/util/concurrent/CompletableFuture.html#failedFuture(java.lang.Throwable)). – Boris the Spider Mar 30 '18 at 21:08
-
I think there are many of tutorials about it like https://www.callicoder.com/java-8-completablefuture-tutorial/ and examples like https://dzone.com/articles/20-examples-of-using-javas-completablefuture I'm not really sure what you mean since you already mentioned the equivalent already! – Al-Mothafar Mar 30 '18 at 21:09
-
@BoristheSpider It looks like that feature is only available in Java 10. I should have specified, but I'm looking for the answer in Java 8. – battmanz Mar 30 '18 at 21:13
-
@Al-Mothafar I have not mentioned the equivalent. I'm *not* looking for an equivalent class, I'm looking for an equivalent method to Promise.reject. – battmanz Mar 30 '18 at 21:14
-
1First, Java 9 - not 10. Second, yes - if you want code for obsolete versions of Java then it is best to specify that in the question. – Boris the Spider Mar 30 '18 at 21:15
-
That link you posted sent me to the docs for java 10. I see that it's also available in Java 9. – battmanz Mar 30 '18 at 21:21
-
Indeed. Given that is the current version of Java, it makes sense to reference those documents. – Boris the Spider Mar 30 '18 at 21:21
-
So do you know the answer in Java 8? – battmanz Mar 30 '18 at 21:24