0

I wrote two classes look like this

class SomeClient {

    ResponseEntity<SomeResponse> getSome(...) { // SomeResponse is a concrete class
    }

    ResponseEntity<SomeOtherResponse> getSomeOther(...) { // SomeOtherResponse is a concrete class
    }
}

class SomeReactiveClient {

    Mono<SomeResponse> getSome(...) {
    }

    Mono<SomeOtherResponse> getSomeOther(...) {
    }
}

These two methods in each classes has same name and parameters. And only diffs for their return type.

Can I define an interface with an generic type parameter for ResponseEntity and Mono?

Say,

interface ISomeClass<T> {

    T<SomeResponse> getSome();

    T<SomeOtherResponse> getSomeOther();
}

Is there any design pattern for this?

Mario Galic
  • 47,285
  • 6
  • 56
  • 98
Jin Kwon
  • 20,295
  • 14
  • 115
  • 184
  • 1
    I think this is called "higher kinded types", which is not available in Java. – Sweeper Jul 31 '20 at 06:29
  • https://medium.com/@johnmcclean/simulating-higher-kinded-types-in-java-b52a18b72c74 seems a bit hacky for me, but maybe it helps – aBnormaLz Jul 31 '20 at 06:32
  • Does this answer your question? [Higher-kinded generics in Java](https://stackoverflow.com/questions/876948/higher-kinded-generics-in-java) – aBnormaLz Jul 31 '20 at 06:33

0 Answers0