为了账号安全,请及时绑定邮箱和手机立即绑定

关于System.gc()的执行?

关于System.gc()的执行?

元芳怎么了 2019-03-13 14:15:55
package FinalizeTest;public class Person {        public Person(){        System.out.println("person created");    }    @Override    protected void finalize() throws Throwable {        // TODO Auto-generated method stub        System.out.println("gc ");        throw new Exception("no effect");    }}package FinalizeTest;public class MainTest {    /**     * @param args     */    public static void main(String[] args) {        // TODO Auto-generated method stub        Person per = new Person();        per = null;        System.gc();        System.out.println("hello world");    }}输出为person createdhello worldgc 代码如上所示, 求解释为什么hello world会在gc之前输出??
查看完整描述

4 回答

  • 4 回答
  • 0 关注
  • 639 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号