现在的位置: 首页 > 综合 > 正文

关于Wrapper Class

2018年05月10日 ⁄ 综合 ⁄ 共 548字 ⁄ 字号 评论关闭
public class RunTest{
	public static void main(String[] args) {
		Integer ten=new Integer(10);
		Long nine=new Long(9);
		System.out.println(ten+nine);
		int i=1;
		System.out.println(i+ten); 
	}
}

大家觉得这道题会输出什么?会不会Error?

刚开始我看到的答案是:Error,解释如下:

The wrapper classes cannot be used like primitives.

Wrapper classes have similar names to primitives but all start with upper case letters.Thus in this case we have int as a primitive and Integer as a wrapper.

The objective do not specifically mention the wrapper classes but don't be surprised if they come up .

但是当我真正在试验之后发现竟然可以输出:19、11;

想了想,可能此题是jdk1.4时候的吧,自从v5之后自动拆装箱,就可以输出结果了,应该是这样的。

大家也讨论下。

【上篇】
【下篇】

抱歉!评论已关闭.