private Integer currClasId=7;
for (QChapterVo q : allChapterList) {
Integer qClassID = q.getQClassID();
System.out.print("---");
System.err.print(qClassID);
System.out.println("="+qClassID.TYPE+"="+currClasId+"--"+currClasId.TYPE);
System.out.print("currClasId==7 is ");
System.out.println(currClasId==7);
System.out.print("qClassID==7 is ");
System.out.println(qClassID==7);
System.out.print("qClassID==currClasId is ");
System.out.println(qClassID==currClasId);
打印效果:
---7=int=7--int
currClasId==7 is true
qClassID==7 is true
qClassID==currClasId is false
当时在开发项目,遇到这个,开始感觉是缓存的事,但是清完缓存还是这样......然后,我开始怀疑是不是我记错了,然后写了个demo来测试Integer比较,结果正常,然后我接着跑项目,发现还是这样,不解,
int qClassID = q.getQClassID();
小写int 顺利通过,求解释
犯2了,跟equals记混了,双等是判断对象的引用是否是一个,equals是判断值