File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[] and dot operator

 
shanthisri mocherla
Ranch Hand
Posts: 119
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
can anyone please explain me this.

mybean is a bean of type MyBean.
objects is a List.
params is a Map.

These (objects and params)are the bean properties.

The following statement results in an error.

${mybean["objects"].a}

where as this statement does not give any error.


${mybean["params"].a}


The explanation for this is since "objects " is NOT a Map, a lookup wont be performed as opposed to Map.


can anyone please explain me in detail.
thnks in advance.
shanthi
 
Satish Ramasamy
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The dot operator works only when the left operand is a Bean or Map.

In case of ${mybean["objects"].a}, mybean["objects"] would be evaluated to a List object (which obviously doesn't have a property called "a") hence it results in error.
 
shanthisri mocherla
Ranch Hand
Posts: 119
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Satish
Thanks for yor help.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic