How can I implement the ContactService interface without getting warning about unchecked conversions from the compiler:
interface ContactsService
{
<T extends Response> T execute(Action<T> action);
}
interface Action<T extends Response> { }
interface Response{ }
class GetDetailsResponse implements Response {}
If I return an instance of GetDetailsResponse then I get the warning:
Unchecked overriding: return type requires unchecked conversion
This is an example from the gwt best practices presentation at google io.
I’m guessing you tried something like:
The problem with this is that I might have another class MyResponse that implements Response. Then I can call:
But the execute method returns an instance of GetDetailsResponse, which is incompatible with MyReponse. You need to return the type T, which is given by the action you pass to execute.
As far as I can tell you can’t instantiate a new variable of type T inside execute (not without some unchecked casts anyway). You probably need the action class to have a way to give you a Response instance that you can return from execute. Something like this: