Return to site

JAVA CERTIFICATION QUESTION: The Optional class and null values in Java

· java

Given:

Call of the code below cause an exception:

Which approach will fix the problem? Choose one.

A. Wrap Config in ThreadLocal:

ThreadLocal tl = ThreadLocal.withInitial(() -> cfg);

B. Override put(Object, Object) and setProperty(String, String) to avoid storing null values in the Config class.

C. Use Optional.ofNullable(...) instead of Optional.of(...) in Config

D. Use a Supplier as a second parameter for the BiFunction.

·ꓷ uoᴉʇdo sᴉ ɹǝʍsuɐ ʇɔǝɹɹoɔ ǝɥꓕ

All Posts
×

Almost done…

We just sent you an email. Please click the link in the email to confirm your subscription!

OK