Page 1 of 1

[HD-OCP17/21-Fundamentals Pg 422, Sec. 15.4.3 - order-of-closing-the-resources]

Posted: Fri Sep 27, 2024 5:04 am
by raphaelzintec
"Devicecontaining"
add space -> Device containing

Re: [HD-OCP17/21-Fundamentals Pg 422, Sec. 15.4.3 - order-of-closing-the-resources]

Posted: Sun Sep 29, 2024 12:53 pm
by radupana
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.

Re: [HD-OCP17/21-Fundamentals Pg 422, Sec. 15.4.3 - order-of-closing-the-resources]

Posted: Sun Sep 29, 2024 2:18 pm
by admin
Right. It should be try(Device d1 = new Device(2) , Device d2 = new Device(2)