test.java

来自「高质量Java程序设计 源代码」· Java 代码 · 共 34 行

JAVA
34
字号
package net.betterjava.exception.constructor;

public class Test {
	private static int counter = 0;

	public Test() {
		super();
		counter++;
		throw new RuntimeException("forced exception");
	}

	public static int getCounter() {
		return counter;
	}

	protected void finalize() {
		counter--;
	}

	public static void main(String[] args) {
		for (int i = 0; i < 10; i++) {
			Test newTest = null;
			try {
				newTest = new Test();
			} catch (RuntimeException e) {
				//do nothing				
			}
			if (newTest == null)
				System.out.println("newTest is not created");
		}
		System.out.println(Test.getCounter());
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?