| Author |
HFSJ - Q15 on page 431
|
Chinu Hota
Greenhorn
Joined: Jan 17, 2006
Posts: 14
|
|
Can you please explain why C and F are right answers in this question. I can't really understand the explanation given. What is "a"?? Which will cause errors: A) ${myBean.name} B) ${myBean["name"]} C) ${myBean.objects.a} D) $myBean["params"].a} E) ${myBean.params["a"]} F) ${mybean["objects"].a}
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14685
|
|
This question wants to stress about the difference between accessing a Map and a List in EL. "a" is variable which does not exist. When using a Map, ${myBean["params"].a}, won't because it will search for the key "a" in the map "params", calling containsKey() and get(). However, you can do this with a List only using integers. Here are the details from the spec: - expr-a.identifier-b is equivalent to expr-a["identifier-b"]; - Evaluate expr-a into value-a - Evaluate expr-b into value-b - If value-a is a Map, List, or array: - If value-a is a Map: If !value-a.containsKey(value-b) then return null. Otherwise, return value-a.get(value-b) - If value-a is a List or array: - Coerce value-b to int (using coercion rules) If coercion couldn't be performed: error "a" is not an int, so error is produced.
|
[My Blog]
All roads lead to JavaRanch
|
 |
 |
|
|
subject: HFSJ - Q15 on page 431
|
|
|