Cannot cast from Object to int
作者:互联网
Cannot cast from Object to ** jdk1.7问题
Object[] objs = new Object[5];
objs[0] = 1;
objs[1] = true;
int value = (int)objs[0]; // 会报错
boolean flag = (boolean)objs[1]; //会报错
int value = (Integer)objs[0]; // 换成包装类型即可
boolean flag = (Boolean)objs[1]; //换成包装类型即可
综上所述:jdk1.7之前,大类型强制转小类型时,基本数据类型需要使用包装类。
标签:objs,int,Object,jdk1.7,cast,Cannot,报错,boolean 来源: https://blog.csdn.net/weixin_44688667/article/details/114734387