OiO.lk Blog java Intellij IDEA show Inconvertible types on Webflux switchIfEmpty()
java

Intellij IDEA show Inconvertible types on Webflux switchIfEmpty()


I currently learning webflux and have this method on my project:

  private Mono doBody(
      WebClient.RequestHeadersSpec<?> client, Method method, String methodName,
      Object[] arguments) {
    if (client instanceof WebClient.RequestBodySpec bodySpec) {
      String contentType = metadata.getContentTypes().get(methodName);

      for (ApiBodyResolver bodyResolver : bodyResolvers) {
        if (bodyResolver.canResolve(contentType)) {
          return bodyResolver.resolve(method, arguments)
              .map(bodySpec::body).switchIfEmpty((Mono.just(client));
        }
      }

    }
    return Mono.just(client);
  }

But then, the intellij give the error warning on the switchIfEmpty() method like this:
Inconvertible types; cannot cast 'reactor. core. publisher. Mono<org. springframework. web. reactive. function. client. WebClient. RequestHeadersSpec<capture<?>>>' to 'reactor. core. publisher. Mono<org. springframework. web. reactive. function. client. WebClient. RequestHeadersSpec>'

I mean, isn’t that the same class? Is there any solution for this, or at least any method to suppress the error?

I have tried to cast the mono inside the switchIfEmpty like:
switchIfEmpty((Mono<WebClient.RequestHeadersSpec>) Mono.just(client))

and invalidate caches many-many times



You need to sign in to view this answers

Exit mobile version