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.
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.
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.
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();
Option B value map declaration is wrong. it is having ValueMap<String> which is wrong. So, I guess it is A.
A may cause NPE. so correct answer is B
Should be B