Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

multiple 'chaining' of dot operators

 
Dan Bromberg
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • 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
 
Paul Clapham
Sheriff
Pie
Posts: 20750
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep, you got it. That's exactly how you should analyze that expression.
 
Henry Wong
author
Marshal
Pie
Posts: 20892
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the affirmation, guys!
Hope to pay it forward someday...

Dan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic