📄 test.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -