Umar Umar - 1 month ago 6
Java Question

Java Generics method argument

I am trying to write an interface method, which will take an argument from a class which extends the common Payload.

public String buildRequest(<T> extends RestServicePayLoad payLoad);


purpose is so that any class that implements RestServicePayLoad can take an argument of that type and return a String.

Looks like my generics format is wrong. Please let me know what is the proper format.
Thanks!

Answer

Youre very close

public <T extends RestServicePayLoad> String buildRequest(T payLoad);