System 类中的 gc 方法直接调用了 Runtime 类中的 gc 方法。
final:定义不能被继承的类,不能被覆写的方法,常量。
finally:异常的统一出口。
finalize :Object 类中的方法,对象回收前的收尾方法,即使出现了异常,也不会中断程序的执行。
class Member{
public Member(){
System.out.println("born");
}
@Override
protected void finalize() throws Throwable {
System.out.println("destroy");
}
}
public class Main {
public static void main(String[] args) {
long start = System.currentTimeMillis();
System.out.println(start);
int num = 0;
for (int i = 0; i < 1000000; i++) {
num += i;
}
System.out.println(num);
long end = System.currentTimeMillis();
System.out.println(end);
System.out.println(end - start);
Member member = new Member();
member = null;
System.gc();
}
}