• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

multiple 'chaining' of dot operators

 
Ranch Hand
Posts: 63
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I see a statement like:

File codeLoc = new File(protectionDomain.getCodeSource().getLocation().getFile());

is there a process by which I can break down each of the "dots"? i.e., should I always resolve the leftmost method protectionDomain.getCodeSource(), after I get its return value use it on the following method getLocation(), get its return value and use it on the next method getFile())...etc... ? I've never seen a decent explanation when the dots operators are chained together like this and would just like to confirm.

Thanks in advance to all those who reply.
Dan
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep, you got it. That's exactly how you should analyze that expression.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dan Bromberg wrote:I've never seen a decent explanation when the dots operators are chained together like this and would just like to confirm.



As with any operator, it is dependent on precedence and the associativity. Since they are all the same operator (chain of dot operators), then only the assoc matters. And in the case of the dot operator, the assoc is left to right.

Agreed with Paul. What you described is correct.

Henry
 
Dan Bromberg
Ranch Hand
Posts: 63
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the affirmation, guys!
Hope to pay it forward someday...

Dan
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic