mercredi 4 août 2021

How to implement a generic interface that extends another generic interface?

I am new to Java and working on implementing generic interfaces and that's where I'd love some help.

I want to implement a generic interface in Java that extends another interface. This is how the current interface structure looks like -

interface ItemsProviderInterface<ExtReq, ExtRes> 
extends GenericItemProviderInterface<ItemRequest, ExtReq, ExtRes, ItemResponse> {}


interface GenericItemProviderInterface<Req, ExtReq, ExtRes, Res>{
    ExtReq convertInput(Req req)
    Res convertResponse(ExtRes res)
    ExtRes request(ExtReq req)
}

I want to implement the ItemsProviderInterface interface and provide a definition for convertInput(), convertResponse(), request() methods.

Maybe something like -

class itemsProvider<> implements ItemsProviderInterface<>

I am not sure which generic type to define the class with.. the ones corresponding to ItemsProviderInterface or GenericItemProviderInterface. I read up a lot of blog posts and searched StackOverflow for a similar question but couldn't find one. Any help is HUGELY appreciated.

Aucun commentaire:

Enregistrer un commentaire