"Devicecontaining"
add space -> Device containing
[HD-OCP17/21-Fundamentals Pg 422, Sec. 15.4.3 - order-of-closing-the-resources]
Moderator: admin
-
- Posts: 167
- Joined: Sun Apr 21, 2024 10:43 am
- Contact:
-
- Posts: 28
- Joined: Fri Feb 09, 2018 11:50 am
- Contact:
Re: [HD-OCP17/21-Fundamentals Pg 422, Sec. 15.4.3 - order-of-closing-the-resources]
In the code snippet provided (TestClass and Device), it says that
"""
You should observe the following points:
1. Resources are opened in the order specified in the try clause (Device 1 and then Device 2).
"""
However, this is not because of the order in the try clause, it's because of the order of the constructor calls. We can change the try from
try(d1; Device d2 = new Device(2)){
to
try(Device d2 = new Device(2); d1){
and the output would still be
Device 1 opened
Device 2 opened
because d1 is constructed before d2.
"""
You should observe the following points:
1. Resources are opened in the order specified in the try clause (Device 1 and then Device 2).
"""
However, this is not because of the order in the try clause, it's because of the order of the constructor calls. We can change the try from
try(d1; Device d2 = new Device(2)){
to
try(Device d2 = new Device(2); d1){
and the output would still be
Device 1 opened
Device 2 opened
because d1 is constructed before d2.
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: [HD-OCP17/21-Fundamentals Pg 422, Sec. 15.4.3 - order-of-closing-the-resources]
Right. It should be try(Device d1 = new Device(2) , Device d2 = new Device(2)
Who is online
Users browsing this forum: No registered users and 25 guests