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.
about enthuware.ocpjp.ii.v11.2.3359
Moderator: admin
-
- Posts: 3
- Joined: Fri Sep 20, 2019 11:53 am
- Contact:
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: about enthuware.ocpjp.ii.v11.2.3359
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.
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.
If you like our products and services, please help us by posting your review here.
-
- Posts: 17
- Joined: Sun Sep 23, 2018 4:10 am
- Contact:
Re: about enthuware.ocpjp.ii.v11.2.3359
So the argumentation here is that AutoCloseable is newer/better and hence SHOULD be implemented rather than Closeable?
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: about enthuware.ocpjp.ii.v11.2.3359
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.
Try with resource doesn't care about Closeable and should not be implemented if it is not required for other reasons.
If you like our products and services, please help us by posting your review here.
-
- Posts: 17
- Joined: Sun Sep 23, 2018 4:10 am
- Contact:
Re: about enthuware.ocpjp.ii.v11.2.3359
Sorry, I got confused there. Thanks for the explanation.
Who is online
Users browsing this forum: Bing [Bot] and 112 guests