((Integer)session.getAttribute("count")).intValue()与 (Integer)session.getAttribute("count") 有神马不同?为什么已经强制转换成了 Integer 还要加一个 intValue() ?
解决方案 »
- checkbox只选中第一个
- 在Ext.FormPanel 的items:[] 属性中如何添加按钮
- 【求助】The requested resource (/news/index.html) is not available.
- 能免费告个问题吗?IE的后退键的代码?比如我点后退就能回到上一个页!谢谢!
- 有那位用过分页的pager-taglib.jar包请进!
- 请教各位高手:那里有Tomcat下载,急用!!!
- 关于Linux下Tomcat和Apache整合的问题。
- JSP中如何对超级链接进行编码,从而对用户屏蔽具体的传递参数?
- 如何防止用户更新页面刷新计数器!
- 表单提交问题
- 网上照片上传功能
- 头疼了,请教各位一个ie兼容性 的问题
intValue 返回的就是一个int的值
(Integer)session.getAttribute("count") 则是一个Integer对象
第二个只是转换成Integer
第二个转换成Integer对象,放在堆空间里
int默认值为0,Integer默认为null
至于为什么先Integer,后int呢?由于【session.getAttribute("count")】是Object,不能直接转int,所以需要先转Integer,然后通过intValue来转成int。另外这里还有一个隐患,【session.getAttribute("count")】可能为空,这样再.intValue()的话就会抛空指针异常。
所以最好还是分开写,先判断一下:Integer countI = (Integer)session.getAttribute("count");
int count = 0;
if (countI != null) {
count = countI.intValue();
}