Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFSJ - Q15 on page 431

 
Chinu Hota
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic