AD0-E103 Exam QuestionsBrowse all questions from this exam

AD0-E103 Exam - Question 27


A developer is creating a custom method. This method must return a String property y from child x. the method must use only Sling APIs.

How should the developer retrieve property y of node x, and node x may or may NOT exist?

A.

B.

C.

D.

Show Answer
Correct Answer:

To retrieve property 'y' of node 'x' using Sling APIs, and considering the possibility that node 'x' may or may not exist, the correct approach involves checking for null values to avoid NullPointerException (NPE). The correct approach is shown in option B. Option B ensures that null checks are properly handled before accessing the properties, which avoids NPEs. The ValueMap is correctly retrieved and used to get the property 'y'. Hence, the correct answer is B.

Discussion

4 comments
Sign in to comment
heenamadan
Jun 21, 2020

Should be B

pkg82
Jun 22, 2020

A may cause NPE. so correct answer is B

kasyap1125
Oct 16, 2020

Option B value map declaration is wrong. it is having ValueMap<String> which is wrong. So, I guess it is A.

chunpin
Jan 9, 2021

Answer: B -------------------------------------------------------------- A: will cause nullpointer, hence wrong C: getProperties return PropertyIterator , hence wrong D: node does not have method getValueMap(), hence wrong B: should have ValueMap map = x.getValueMap();