Return to site

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

· java,ocp

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ɔ ǝɥꓕ