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.