Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 922987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:07:14+00:00 2026-05-15T19:07:14+00:00

How can I implement the ContactService interface without getting warning about unchecked conversions from

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:07:15+00:00Added an answer on May 15, 2026 at 7:07 pm

    I’m guessing you tried something like:

    class MyService implements ContactsService {
        @Override
        public <T extends Response> T execute(Action<T> action) {
            return (T)new GetDetailsResponse();
        }
    }
    

    The problem with this is that I might have another class MyResponse that implements Response. Then I can call:

    Action<MyResponse> action = new Action<MyResponse>();
    // you can't actually instantiate an interface, just an example
    // the action should be some instance of a class implementing Action<MyResponse>
    MyReponse r = myService.execute(action);
    

    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:

    interface Response {
        void setWhatever(String value);
    }
    
    interface Action<T extends Response> {
        T getResponse();
    }
    
    class MyAction implements Action<GetDetailsResponse> {
        @Override
        public GetDetailsResponse getResponse() {
            return new GetDetailsResponse();
        }
    }
    
    class MyService implements ContactsService {
        @Override
        public <T extends Response> T execute(Action<T> action) {
            T response = action.getResponse();
            // do something to Response here like
            response.setWhatever("some value");
            return response;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am thinking of how I can implement std::vector from the ground up. How
In C#, I can implement a generic interface twice on one class, using two
In java I can implement the composite design pattern as follows: interface Component{ void
As a SOAP web services developer, I'm curious about what techniques I can implement
I know how can implement listview without using listactivity.But i dont know how get
I wonder if we can implement and fetch data from different datasources into a
I can implement both variants - it's easy. But I'm interested: what approach is
How can implement reordring in winforms datagridview by using the feature of drag and
Can someone please tell me how I can implement the following line of pseudo-code.
Anyone knows how i can implement re-arrangable divs (Drag the divs around on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.