I created abstract class for my ArrayList
holders
public abstract class ArrayHolder {
Gson g = new Gson();
}
used like
public class MyHolder extends ArrayHolder {
ArrayList<MyType> myList = new ArrayList<MyType>();
}
I would like to create abstract function to fill this ArrayList
from String
and Type
argument
like this (String data
is JSON in String
) : This function should be rewritten
public ArrayList<T> arrayType(String data, T type){
return g.fromJson(data, new TypeToken<ArrayList<type>(){}.getType());
}
to use it in subclass
public void fillData(String data){
myList = arrayType(data, MyType.class);
}
How can I do this properly?
Thanks
Try this...
use
Do it like this:
I haven't dealt with generic typed methods, but from what I've seen, this is right.