forked from Hesenius/SafariJava17CertStudy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package autoclose; | ||
class AC implements AutoCloseable { | ||
private String name; | ||
public AC(String name) { this.name = name; } | ||
@Override public void close() { | ||
System.out.print("Closing " + name); | ||
} | ||
} | ||
public class Ex1 { | ||
public static void main(String[] args) { | ||
var ac0 = new AC("zero"); | ||
try ( | ||
var ac1 = new AC("one"); | ||
var ac2 = new AC("two"); | ||
ac0; | ||
) { | ||
} | ||
// ac0 = null; // must be final or effectively final! | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package autoclose; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.sql.SQLException; | ||
|
||
class AC4 implements AutoCloseable { | ||
@Override | ||
public void close() throws Exception { | ||
throw new SQLException(); | ||
} | ||
} | ||
|
||
class Q7 { | ||
public static void main(String[] args) { | ||
try { | ||
doIt(); | ||
} catch (Throwable t) { | ||
t.printStackTrace(); | ||
} | ||
} | ||
public static void doIt() throws Throwable { | ||
try ( | ||
var one = new AC4(); | ||
var two = new AC4(); | ||
) { | ||
// throw new FileNotFoundException(); | ||
} | ||
} | ||
} | ||
|