对象销毁之前进行某些操作

class Person {
    private String name;
    private int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String toString() {
        return "Nmae:" + this.name + ",Age:" + this.age;
    }

    public void finalize() {
        System.out.println("Object be released---->" + this);
    }
}

public class SystemDemo04 {
    public static void main(String[] args) {
        Person person = new Person("VON KENMO", 38);
        person = null;
        System.gc();
    }
}

原文地址:https://www.cnblogs.com/vonk/p/3910214.html