Stay clear of the void

So I learned this the hard way, but in reactive programming, aka my WebFlux project. Do not ever use Void as a type. Just wrap it in something you can propagate like Object, String or Boolean or something else.

It gets really difficult, like impossible, do to things like return a Mono<Void> that actually is returning some object. You cannot return null as that will internally by construed to be an empty Mono and won't trigger downstream. So that goes out the window, how about instantiating one via Void.TYPE.newInstance() ? Well that is not without it's own problems. It is deprecated and most likely can fail in any number of reasons plus make your code really unmanageable.

Never ever ever ever use it ?

Well you can if you know it is the end of the line, but for instance doing a .onErrorResume(Function<Throwable, ? extends Void>) is not a cool thing to do. Even if a Mono.then() will fix the problem it just makes everything so unnecessarily complex.

#java #reactive