• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

EL . and [] operators

 
Ranch Hand
Posts: 60
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a query about a question in the HFSJ book


Which about EL access operators are true?

a. Anywhere the . (dot) operator is used, the [] could be used instead.
b. Anywhere the [] operator is used, the . (dot) could be used instead.
c. If the . (dot) operator is used to access a bean property but the property doesn't exist, then a runtime exception is thrown.
d. There are some situations where the . (dot) operator must be used and other situations where the [] operator must be used.



Now the answers are A + C. I chose A, C + D. It lists the reason for D not being correct as


Option D is incorrect because the dot operator can always be converted to the [] operator



Whilst it's true that the [] operator can be used for JavaBeans, Maps, Lists and Arrays. It's not true that the . (dot) operator can be used for Lists and Arrays. So there are some situations where you shouldn't use the . (dot) operator, so therefore D is a valid option. Am I right?
 
Creator of Enthuware JWS+ V6
Posts: 3412
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,

So there are some situations where you shouldn't use the . (dot) operator, so therefore D is a valid option. Am I right?


These questions are always tricky and sometimes they could be ambigious, but in your reasoning you have found:

  • that the [] operator must be used with a list or an array
  • but
  • you haven't found the situation that the . operator must be used because the [] operator fails to work

  • that is why D is not correct

    Regards,
    Frits
     
    Paul Statham
    Ranch Hand
    Posts: 60
    1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Ah ok I see it's all in the word must! Dot is Never a must!
     
    Ranch Hand
    Posts: 256
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Paul Statham wrote:Ah ok I see it's all in the word must! Dot is Never a must!


    That is the catch . You can always replace a "." with []
     
    CAUTION! Do not touch the blades on your neck propeller while they are active. Tiny ad:
    Gift giving made easy with the permaculture playing cards
    https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
    reply
      Bookmark Topic Watch Topic
    • New Topic