设为首页 加入收藏

TOP

关于finalize()方法的解释。
2011-06-09 12:57:21 来源: 作者: 【 】 浏览:756次 评论:0
原题:
我在thinking in java中看见以下一段代码。
//:Garbage.java
//Demonstration of the garbage
//collector and finalization
class Chair {
    static boolean gcrun=false;
    static boolean f=false;
    static int created=0;
    static int finalized=0;
    int i;
    Chair(){
        i=++created;
        if(created==47)
            System.out.println("Created 47");
    }
    protected void finalize(){
        if(!gcrun){
            gcrun=true;
            System.out.println(
                "Beginning to finalize after"+created+
                "Chairs have been created");
        }
    if(i==47){
        System.out.println(
            "Finalizing Chair #47,"+
            "Setting flag to stop Chair creation");
        f=true;
    }
    finalized++;
    if(finalized>=created)
        System.out.println(
您看到此篇文章时的感受是:
Tags: 责任编辑:administrator
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到QQ空间
分享到: 
上一篇Beginner: Using Servlets to dis.. 下一篇JDBC 入门

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

相关栏目

最新文章

图片主题

热门文章

推荐文章

相关文章

广告位