1

I speak Spanish, use the translator to ask this question, Sorry for the spelling.

Also, do not be like asking exactly what I want to do.

I want to create a list of an object passing through parameter.

public void createListUnknown(? Class myClass?  or  ? Object myObject?) {

    List<myClass> my_list;

       //or

    List<myObject> my_list;


}

example use:

public class Model{
    public String name;
    public String age;
}

as it should be?

createListUnknown(?? MyModel ??)

Basically I want to create a list with an object that comes parameter to a function

An example where you want to apply is the following:

    //final GsonModelUsuariosLoginGet gsonModelUsuariosLoginGet
//= gson.fromJson(responseData, GsonModelUsuariosLoginGet.class);
return gson.fromJson(responseData, httpObject.getObjectGet().getClass());

and

Object aClass = httpObject.getObjectGet().getClass();

List< httpObject.getObjectGetClass() > aClasses;

Type collectionType = new TypeToken<List<aClass>>(){}.getType();
final List<GsonModelArticulos> articulos = gson.fromJson(responseData, collectionType);
jojemapa
  • 873
  • 2
  • 10
  • 21
  • You edited your question to add an exemple but you don't show where you want to use your method. – Arthur Rey Jun 08 '16 at 23:35
  • Thanks, First of all thanks. probe your code and tell me the following message: "list is not abstract can be instantiated." this also fails : return new List() = new ArrayList(); – jojemapa Jun 08 '16 at 23:49
  • This will suit your answer : http://stackoverflow.com/questions/6231973/difference-between-list-list-listt-liste-and-listobject – RicardoVallejo Jun 09 '16 at 00:25

1 Answers1

3

create list

public <T> List<T> makeList(Class<T> type) {
        return new ArrayList<T>();
    }

get type list

Using the Type interface.

private <T> Type getType(Class<T> type) {
        Type typeOfObjectsListNew = new TypeToken<ArrayList<T>>() {}.getType();
        return typeOfObjectsListNew;
    }
Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
jojemapa
  • 873
  • 2
  • 10
  • 21