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 7675817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:03:10+00:00 2026-05-31T17:03:10+00:00

I’m writing an API on Android that will be used by an existing application,

  • 0

I’m writing an API on Android that will be used by an existing application, which I’m going to call the client. There is a lot of client code and I don’t really want to modify it. Right now the API implements a callback method as an interface. In order to save my self from writing lots of boiler plate code I decided to use generics and extensible classes. This design decision is making my API’s Callback interface use generics. In turn this is causing the complier to flag the client as needing to to specify type parameters where the callback is implemented. I don’t want to cause the client to have to use type parameters. In effect I want to shield the client code from having to specify types and hopefully prevent the client from specifying the wrong type.

Here is an example:

Example of an extensible API class to encapsulate basic functionality:

public abstract class BaseAPI<T> {
   Callback mCallBack;   

   public BaseAPI(Callback<T> callback) {
      mCallBack = callback;
   }

   public void doSomething() {
      T response = getResponse();
      if (mCallBack != null) {
         mCallBack.onCallback(response)
      }
   }

   public abstract T getResponse();

   public interface Callback<T> {
      public void onCallback(T response);
   }
}

Example class that extends BaseAPI:

public class ExampleAPI extends BaseAPI<String> {

   public ExampleAPI(Callback<String> callback) {
      super(callback):
   }

   public String getResponse() {
      String response = "blah";
      return response;
   }
}

Example client code (This is how I want it to look):

public class ClientView extends Activity implements Callback {
   TextView mTextView;

   onCreate() {
      //pretend normal setup code is here

      new ExampleAPI(this).doSomething();
   }

   onCallback(String response) {
       mTextView.setText(response);
   }
}

Example client code (This is the complier wants it to look):

public class ClientView extends Activity implements Callback<String> {
   TextView mTextView;

   onCreate() {
      //pretend normal setup code is here

      new ExampleAPI(this).doSomething();
   }

   onCallback(String response) {
       mTextView.setText(response);
   }
}

Any ideas? Does this make sense?

  • 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-31T17:03:12+00:00Added an answer on May 31, 2026 at 5:03 pm

    It seems to me like you have competing objectives, and that the solution is to simply move the mess somewhere else.

    What about implementing an intermediate type hiding interface, like StringCallback:

    interface StringCallback extends Callback<String>
    

    Or more abusively, you can just mask it with an Object:

    interface ObjCallback extends Callback<Object>
    

    Then ClientView would implement one of these interfaces instead, at the end of the day your base API stuff should be happy, and your client code doesn’t have to carry the generics.

    I’m not entirely sure why you want to do this, your client code should just specify the types.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.