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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:39:35+00:00 2026-06-16T11:39:35+00:00

I have a following problem: I had a few methods that are basically used

  • 0

I have a following problem:

I had a few methods that are basically used to get something from Salesforce.

Here is an example:

 public Map<String, Customer> findSomethingByIds(String[] somethingIds) throws... {
     return binding.findSomethingByIds(somethingIds);
 }

For a number of reasons I needed to retry the execution of this method in a very rare cases (f.e session expires etc.), so I used this.

So now I have something like this:

 public Map<String, Something> findSomethingByIds(final String[] somethingIds) throws ... {       
    Map<String, Something> myList = null;                
    Callable<Map<String, Something>> task = new Callable<Map<String, Something>>() {
        @Override
        public Map<String, Something> call() throws Exception {
            return binding.findSomethingByIds(somethingIds);
        }
    };

    RetriableTask<Map<String, Something>> r = new RetriableTask<>(2, 1000, task);
    try {
        myList = r.call();
    } catch (Exception e) {
        // Ex. handling
    }
    return myList;
}

Now, there are a lot of such methods in my code, so if I want to use the RetriableTask interface I have to add a lot of code to those methods, similar to the one above, which I want to avoid at all costs. All those methods pretty much return something different, so I can’t use a Factory here (or I don’t know how). Does anyone know any solution for this? Any help would be appreciated.

  • 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-06-16T11:39:36+00:00Added an answer on June 16, 2026 at 11:39 am

    If you have a method doing something similar and the only difference is the return type, try using generics:

    public Map<String, T> findSomethingByIds(final String[] somethingIds) throws ... {       
    
    }
    

    This will allow you to perform equivalent processing on different object types without copying and pasting code everywhere.

    Responding to the comments, if they take different parameter types, you can still use generics in the parameters. If you mean they have a different number of parameters (i.e., have a completely different signature), then you can create wrapper methods which perform the processing which is unique to that object type, and after that you can pass control to the generic method for the processing which is common to all object types.

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

Sidebar

Related Questions

Hi i am new to Spring and I have a following problem: I had
I have had the following problem for a while and I am really not
I have the following problem, from c++ I send huge string[] to java. huge
I have had the problem a few times now while working on projects and
I have following problem: I have to make a ASP.NET Webapplication with a two-row
I have following problem: I have built a tabbar application with 4 tabs. I
I have following problem, Code: String a=Yeahh, I have no a idea what's happening
Hi i have following Problem. I write a Mediawiki Extension where i need some
I am using GWT/JAVA for development. I have following problem: I want to remove
I have the following problem. I have embedded a map using Google Maps' API.

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.