开发中遇到一个问题,父类转子类问题
public class StudentCityArea extends Student{
private static final long serialVersionUID = -4004994377623377635L;
private String province;
private String city;
private String area;
private String remark;
}
直接使用强转出问题
Student student=new Student();
StudentCityArea StudentCityAread123=(StudentCityArea)student;
Exception in thread "main" java.lang.ClassCastException
解决办法,利用json 转化生成子类,解决问题
Student student=new Student();
String studentStr= JSONObject.toJSONString(student);
StudentCityArea studentCityArea
=JSONObject.parseObject(studentStr,StudentCityArea.class);