aspose file tools
The moose likes Beginning Java and the fly likes multiple 'chaining' of dot operators Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "multiple Watch "multiple New topic
Author

multiple 'chaining' of dot operators

Dan Bromberg
Ranch Hand

Joined: Oct 18, 2005
Posts: 51
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


Thanks in advance to all who reply,
Dan
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 19357
    
  10

Yep, you got it. That's exactly how you should analyze that expression.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19532
    
  42

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Dan Bromberg
Ranch Hand

Joined: Oct 18, 2005
Posts: 51
Thanks for the affirmation, guys!
Hope to pay it forward someday...

Dan
 
Have you tried LearnNowOnline? http://www.learnnowonline.com/
 
subject: multiple 'chaining' of dot operators