Skip to content

Commit b625c3d

Browse files
committed
HashMap和Hashtable的区别
1 parent 0fe2b75 commit b625c3d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
##finally语句是否一定会执行
2+
###问题
3+
在try/catch块中我加了return语句。那么finally语句是否会调用呢?
4+
代码例子
5+
```java
6+
try {
7+
something();
8+
return success;
9+
}
10+
catch (Exception e) {
11+
return failure;
12+
}
13+
finally {
14+
System.out.println("i don't know if this will get printed out.");
15+
}
16+
```
17+
我知道我可以直接运行看看,但因为我google了一番后,并未发现相关答案,所以我提出了这个问题,大家可以展开讨论
18+
19+
###回答
20+
finally语句会被调用,除了以下情况:
21+
1. 你调用了`System.exit()`
22+
2. 另外一个线程通过[`interrupt`](https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html#interrupt--)中断了当前线程
23+
3. JVM发生crash
24+
25+
26+
//译注:第二点有待验证,评论区有人质疑

0 commit comments

Comments
 (0)