I have model class:
public class RecordSet {
private DateRange daterange;
private Master master;
public DateRange getDaterange() {
return daterange;
}
public void setDaterange(DateRange daterange) {
this.daterange = daterange;
}
public Master getMaster() {
return master;
}
public void setMaster(Master master) {
this.master = master;
}
}
public class DateRange {
private Date ddate;
public Date getDdate() {
return ddate;
}
public void setDdate(Date ddate) {
this.ddate = ddate;
}
}
public class Master {
private String empcode;
private String empname;
private String dept;
public String getEmpcode() {
return empcode;
}
public void setEmpcode(String empcode) {
this.empcode = empcode;
}
public String getEmpname() {
return empname;
}
public void setEmpname(String empname) {
this.empname = empname;
}
public String getDept() {
return dept;
}
public void setDept(String dept) {
this.dept = dept;
}
}
I have a statement like this
List<RecordSet> list = (List<RecordSet>) query.list();
when the above statement get’s executed I’m gettind the list Objects and Each object holds two items(Master,DateRange)?
Could any one How can I get those two model class objects
I’ve tried but facing classcast exception:
List<RecordSet> list = (List<RecordSet>) query.list();
for(int i=0;i<list.size(); i++){
Object set=list.get(i);
Master masetr=(Master)set;
System.out.println(masetr);
}
thanks
The class of the object you’re casting and the class you’re casting it to must be related by inheritance; that is, you can cast an object only to an instance of its class’s sub- or superclass-not to any random class.
Side note: Casting downward in the class hierarchy is automatic, but casting upward is not.