A
Alessandro
Hi all,
I have a method called xml2obj() returning a specific ArrayList
(ArrayList<Ric>), infact I call a specific constructor of Ric class
inside this method. I need to generalize this method for every kind of
object, not only Ric and calling of course their constructor.
I have some problems ... tried using generic ArrayList or
ArrayList<Object> but when calling the constructor I get error.
Constructor will have always this structure constr(String value1,
String value2)
This is the fragment which will be more clear:
// START
*** SPECIFIC METHOD xml2obj with ArrayList<Ric>***
....
public ArrayList<Ric> xml2obj(){
ArrayList<Ric> ricList=new ArrayList<Ric>();
....
ricList.add(new Ric(group,instrument);
return ricList;
}
*** class Ric ***
public class Ric {
private String group;
private String instrument;
//costr
public Ric(String group, String instrument) {
this.group = group;
this.instrument = instrument;
}
public String getGroup() {
return group;
}
public String getInstrument() {
return instrument;
}
}
*** idea of GENERIC METHOD in another class ***
....
public ArrayList<Object> xml2Obj(Document doc, Object obj) {
ArrayList myList=new ArrayList();
....
myList.add(new Object(name1,name2));
}
//END
Any suggestions ??
Thanks and best regards,
Alessandro
I have a method called xml2obj() returning a specific ArrayList
(ArrayList<Ric>), infact I call a specific constructor of Ric class
inside this method. I need to generalize this method for every kind of
object, not only Ric and calling of course their constructor.
I have some problems ... tried using generic ArrayList or
ArrayList<Object> but when calling the constructor I get error.
Constructor will have always this structure constr(String value1,
String value2)
This is the fragment which will be more clear:
// START
*** SPECIFIC METHOD xml2obj with ArrayList<Ric>***
....
public ArrayList<Ric> xml2obj(){
ArrayList<Ric> ricList=new ArrayList<Ric>();
....
ricList.add(new Ric(group,instrument);
return ricList;
}
*** class Ric ***
public class Ric {
private String group;
private String instrument;
//costr
public Ric(String group, String instrument) {
this.group = group;
this.instrument = instrument;
}
public String getGroup() {
return group;
}
public String getInstrument() {
return instrument;
}
}
*** idea of GENERIC METHOD in another class ***
....
public ArrayList<Object> xml2Obj(Document doc, Object obj) {
ArrayList myList=new ArrayList();
....
myList.add(new Object(name1,name2));
}
//END
Any suggestions ??
Thanks and best regards,
Alessandro