About Question enthuware.ocpjp.v11.2.3359 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
jorgeruiz
Posts: 8
Joined: Sat Jan 20, 2018 1:36 pm
Contact:

About Question enthuware.ocpjp.v11.2.3359 :

Post by jorgeruiz »

Hi,
The explanation of the 2nd option "Device should implement Closeable and override close() method." is reasonable. Basically is a matter of how the response or question is using "should" and not "may".

But, there is no explanation on why the "Device should implement AutoCloseable..."
Is it because is more generic than Closeable?
Because its close method is not required to be idempotent?

Would you please clarify?

admin
Site Admin
Posts: 10419
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v11.2.3359 :

Post by admin »

It should implement AutoCloseable because that is the minimum that is required for a Device to be used in a try-with-resources statement. Without implementing AutoCloseable the given code will not compile.

Closeable is not required.

Sophia2005
Posts: 4
Joined: Fri May 09, 2025 1:38 am
Contact:

Re: About Question enthuware.ocpjp.v11.2.3359 :

Post by Sophia2005 »

jorgeruiz wrote:
Mon Jan 06, 2025 8:37 am
Hi, Stickman Hook
The explanation of the 2nd option "Device should implement Closeable and override close() method." is reasonable. Basically is a matter of how the response or question is using "should" and not "may".

But, there is no explanation on why the "Device should implement AutoCloseable..."
Is it because is more generic than Closeable?
Because its close method is not required to be idempotent?

Would you please clarify?
Would it make sense to always choose Closeable when designing a class that deals with streams, sockets, or files, given its narrower, IO-specific semantics?

admin
Site Admin
Posts: 10419
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v11.2.3359 :

Post by admin »

No, as you said Closeable is too IO specific. Streams are not necessarily IO specific.

AutoCloseable is meant for anything that can be closed and so that is what should be used.

There is no scenario where Closeable is preferrable to AutoCloseable.

Post Reply

Who is online

Users browsing this forum: Google Adsense [Bot] and 22 guests