Page 1 of 1

about enthuware.ocpjp.ii.v11.2.3359

Posted: Fri Sep 20, 2019 11:57 am
by codeappman@gmail.com
why the 2nd option is not correct?

2) Device should implement Closeable and override close() method // why this is not correct?
5) Device should implement AutoCloseable and override close() method. // answer said only this is correct

Closeable extends AutoCloseable, implementing either of them is valid for try-with-resources. I think the 2nd option is also valid.

Thanks.

Re: about enthuware.ocpjp.ii.v11.2.3359

Posted: Fri Sep 20, 2019 10:16 pm
by admin
The requirement for a try with resource block is AutoCloseable and not Closeable.
If the problem statement were asking about interfaces that may be implemented then Device, the Closeable would have been correct as well. But the problem statement says "should implement". There is no requirement for Closeable. It should implement only AutoCloseable.

Further, since only one option is required to be selected, AutoCloseable is the best option.

Re: about enthuware.ocpjp.ii.v11.2.3359

Posted: Sat Oct 09, 2021 5:18 am
by floryan
So the argumentation here is that AutoCloseable is newer/better and hence SHOULD be implemented rather than Closeable?

Re: about enthuware.ocpjp.ii.v11.2.3359

Posted: Sun Oct 10, 2021 1:08 am
by admin
No, as mentioned in the above response, the argument is that the requirement for a try with resource block is AutoCloseable and not Closeable. So, that is what you should implement.
Try with resource doesn't care about Closeable and should not be implemented if it is not required for other reasons.

Re: about enthuware.ocpjp.ii.v11.2.3359

Posted: Wed Oct 13, 2021 11:57 am
by floryan
Sorry, I got confused there. Thanks for the explanation.