关于对象初始化的问题 本帖最后由 yaoguicheng 于 2010-01-01 10:39:41 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 感觉和计数器的清零一样。呵呵。只是感觉两个try块互不影响。初始值都要为null;。 wc = null;//very import try{ try{ wc = new WithCleanup(true); }catch(AbortedConstruction e) { System.out.println("Caught " + e); }finally { System.out.println("In finally 2,preparing to clean up"); wc.cleanup(); } }catch(Exception e){ System.out.println("Caught exception "+ e); }我们讨论一下这部分:(1) wc = null开始的时候wc引用没有指向任何有效的WithCleanup对象(2) 当第一个try块中执行 wc = new WithCleanup(true);的时候,由于构造器内抛出了异常,一次对象并没有构造成功,也就是说new并没有成功的返回一个有效WithCleanup对象的内存地址。因此wc仍然是null(3) 最后执行finally块中的wc.cleanup();是一定会抛出java.lang.NullPointerException的运行时异常。接着虚拟机退出,程序再也不继续执行下去了。 linux 下怎么查看java API? 具体类没有实现父类抽象方法居然也能编译通过 有关在java 中加单选框! 学JAVA的兄弟姐妹请进 请问有什么方法提高使用大量浮点运算时的性能 jtable的行数增减 helloworld能通过,其它程序有java.lang.NoSuchMethodError??? 各位兄弟姐妹,救救我先。。。。。。。! 为什么AppletViewer不能看继承JApplet的java小程序 谁知道那有VISUALAGE最高版本下载?一定给分。 对象序列号问题? 回帖中引用功能实现--java正则表达式如何实现
try{
try{
wc = new WithCleanup(true);
}catch(AbortedConstruction e) {
System.out.println("Caught " + e);
}finally {
System.out.println("In finally 2,preparing to clean up");
wc.cleanup();
}
}catch(Exception e){
System.out.println("Caught exception "+ e);
}
我们讨论一下这部分:(1) wc = null开始的时候wc引用没有指向任何有效的WithCleanup对象
(2) 当第一个try块中执行 wc = new WithCleanup(true);的时候,由于构造器内抛出了异常,一次对象并没有构造成功,也就是说new并没有成功的返回一个有效WithCleanup对象的内存地址。因此wc仍然是null
(3) 最后执行finally块中的wc.cleanup();是一定会抛出java.lang.NullPointerException的运行时异常。接着虚拟机退出,程序再也不继续执行下去了。