java 里面继承关系里 父类对象可以强制转换成子类吗? 并把父类对象的属性赋予给子类。。。??
//父类
public class OpenDoorInfo {
private Long oid;
private String omanId;
private String omanName;
private String ophone;
private Date oouttime;
private String ocarid;
private String otype;
private Short isdelete;
private String oareaName;
private String ovillageidName;
private String ocameraName;
private String ohouseNum;
private String odeivName;
private Date createTime;
private long ocameraId;
public OpenDoorInfo() {
}
public OpenDoorInfo(Long oid, String omanId, String omanName, String ophone, Date oouttime, String ocarid,
String otype, Short isdelete, String oareaName, String ovillageidName, String ocameraName, String ohouseNum,
String odeivName, Date createTime, long ocameraId) {
super();
this.oid = oid;
this.omanId = omanId;
this.omanName = omanName;
this.ophone = ophone;
this.oouttime = oouttime;
this.ocarid = ocarid;
this.otype = otype;
this.isdelete = isdelete;
this.oareaName = oareaName;
this.ovillageidName = ovillageidName;
this.ocameraName = ocameraName;
this.ohouseNum = ohouseNum;
this.odeivName = odeivName;
this.createTime = createTime;
this.ocameraId = ocameraId;
}
/**
* @return the oid
*/
public Long getOid() {
return oid;
}
/**
* @param oid the oid to set
*/
public void setOid(Long oid) {
this.oid = oid;
}
/**
* @return the omanId
*/
public String getOmanId() {
return omanId;
}
/**
* @param omanId the omanId to set
*/
public void setOmanId(String omanId) {
this.omanId = omanId;
}
/**
* @return the omanName
*/
public String getOmanName() {
return omanName;
}
/**
* @param omanName the omanName to set
*/
public void setOmanName(String omanName) {
this.omanName = omanName;
}
/**
* @return the ophone
*/
public String getOphone() {
return ophone;
}
/**
* @param ophone the ophone to set
*/
public void setOphone(String ophone) {
this.ophone = ophone;
}
/**
* @return the oouttime
*/
public Date getOouttime() {
return oouttime;
}
/**
* @param oouttime the oouttime to set
*/
public void setOouttime(Date oouttime) {
this.oouttime = oouttime;
}
/**
* @return the ocarid
*/
public String getOcarid() {
return ocarid;
}
/**
* @param ocarid the ocarid to set
*/
public void setOcarid(String ocarid) {
this.ocarid = ocarid;
}
/**
* @return the otype
*/
public String getOtype() {
return otype;
}
/**
* @param otype the otype to set
*/
public void setOtype(String otype) {
this.otype = otype;
}
/**
* @return the isdelete
*/
public Short getIsdelete() {
return isdelete;
}
/**
* @param isdelete the isdelete to set
*/
public void setIsdelete(Short isdelete) {
this.isdelete = isdelete;
}
/**
* @return the oareaName
*/
public String getOareaName() {
return oareaName;
}
/**
* @param oareaName the oareaName to set
*/
public void setOareaName(String oareaName) {
this.oareaName = oareaName;
}
/**
* @return the ovillageidName
*/
public String getOvillageidName() {
return ovillageidName;
}
/**
* @param ovillageidName the ovillageidName to set
*/
public void setOvillageidName(String ovillageidName) {
this.ovillageidName = ovillageidName;
}
/**
* @return the ocameraName
*/
public String getOcameraName() {
return ocameraName;
}
/**
* @param ocameraName the ocameraName to set
*/
public void setOcameraName(String ocameraName) {
this.ocameraName = ocameraName;
}
/**
* @return the ohouseNum
*/
public String getOhouseNum() {
return ohouseNum;
}
/**
* @param ohouseNum the ohouseNum to set
*/
public void setOhouseNum(String ohouseNum) {
this.ohouseNum = ohouseNum;
}
/**
* @return the odeivName
*/
public String getOdeivName() {
return odeivName;
}
/**
* @param odeivName the odeivName to set
*/
public void setOdeivName(String odeivName) {
this.odeivName = odeivName;
}
/**
* @return the createTime
*/
public Date getCreateTime() {
return createTime;
}
/**
* @param createTime the createTime to set
*/
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
/**
* @return the ocameraId
*/
public long getOcameraId() {
return ocameraId;
}
/**
* @param ocameraId the ocameraId to set
*/
public void setOcameraId(long ocameraId) {
this.ocameraId = ocameraId;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "OpenDoorInfo [oid=" + oid + ", omanId=" + omanId + ", omanName=" + omanName + ", ophone=" + ophone
+ ", oouttime=" + oouttime + ", ocarid=" + ocarid + ", otype=" + otype + ", isdelete=" + isdelete
+ ", oareaName=" + oareaName + ", ovillageidName=" + ovillageidName + ", ocameraName=" + ocameraName
+ ", ohouseNum=" + ohouseNum + ", odeivName=" + odeivName + ", createTime=" + createTime
+ ", ocameraId=" + ocameraId + "]";
}
}
//子类
public class OpenDoorInfoLinkImage extends OpenDoorInfo {
private List<CameraPicture> pictures;
public OpenDoorInfoLinkImage() {
}
public OpenDoorInfoLinkImage(Long oid, String omanId, String omanName, String ophone, Date oouttime,
String ocarid, String otype, Short isdelete, String oareaName, String ovillageidName,
String ocameraName, String ohouseNum, String odeivName, Date createTime, long ocameraId,
List<CameraPicture> pictures) {
super(oid, omanId, omanName, ophone, oouttime, ocarid, otype, isdelete, oareaName, ovillageidName,
ocameraName, ohouseNum, odeivName, createTime, ocameraId);
this.pictures = pictures;
}
public List<CameraPicture> getPictures() {
return pictures;
}
public void setPictures(List<CameraPicture> pictures) {
this.pictures = pictures;
}
}
//问题代码??
OpenDoorInfo odi=new OpenDoorInfoLinkImage();
OpenDoorInfoLinkImage ldli=(OpenDoorInfoLinkImage)odi;
报错信息:java.lang.ClassCastException: com.stkj.zjg.model.gzh.OpenDoorInfo cannot be cast to com.stkj.zjg.model.gzh.OpenDoorInfoLinkImage