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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:28:05+00:00 2026-06-11T14:28:05+00:00

After successfully writing one method which does what it should (much shortened sample below)

  • 0

After successfully writing one method which does what it should (much shortened sample below) I want to refactor it to not be limited to return a List of MyEntity but instead a List<SomeType extends MyParentEntity>. So it should be able to accept only those types extending my MyParentEntity but able to specify another type (List<MyOtherEntity>, List<MyAwesomeEntity> etc.).

Shortened example:

 public static List<MyEntity> getFavList(Context context) {

        String prefKey = buildKey( new MyEntity() );
        List<MyEntity> entityList = new ArrayList<MyEntity>();

        SharedPreferences settings = context.getSharedPreferences(prefKey, 0);

        GSON gson = new GSON();
        MyEntity entity = gson.fromJson(settings.getString(0, null), MyEntity.class);

        entityList.add(entity);

        return entityList;
    }

I googled a lot but I didn’t find the correct approach to make this work without any compiler errors. I’d appreciate any pointers leading to a solution.

  • 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-11T14:28:06+00:00Added an answer on June 11, 2026 at 2:28 pm

    You will need to pass in the Class and the object you are passing to buildKey.

    public static <T extend MyParentEntity> List<T> getFavList(
        Context context, Class<T> clazz, T key
    ) {
    
        String prefKey = buildKey(key);
        List<T> entityList = new ArrayList<T>();
    
        SharedPreferences settings = context.getSharedPreferences(prefKey, 0);
    
        GSON gson = new GSON();
        MyEntity entity = gson.fromJson(settings.getString(0, null), clazz);
    
        entityList.add(entity);
    
        return entityList;
    }
    

    (I don’t know what buildKey is supposed to be.)

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

Sidebar

Related Questions

After logged in successfully, Yii does not executing any page. Showing an error: Error
my problem is after i successfully log in,it is not redirect to page that
I'm writing an automated test to determine whether or not rtf files are successfully
I'm currently writing a multi-process network game server (one gatekeeper process which tells players
I'm writing a simple app with AppEngine, using Python. After a successful insert by
After successfully opening Pop3Folder , and retrieving messages from it, I then sometimes get
After successfully acquiring an oauth_token for a user, I am able to get successful
after successfully building my application the start fails because it relies on config files
I'm using NetDataContractSerializer . After successfully deserializing an object, is there a way to
I need to make a thumbnail of an image after successfully uploaded the image

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.