File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

please explain this syntax

 
nirjari patel
Ranch Hand
Posts: 386
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
doc.addElement("data").addElement("something")

How does this syntax work ?
Does it add "data" and "something" both ?
Does it not need to be added separately ?
If we can ad teo elements in one statement, then can we add three elements in one statement ?

thanks

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the doc ?
 
Greg Charles
Sheriff
Posts: 2984
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whatever "doc" may be, the addElement() method returns "this", that is a reference to the doc object itself. Why? To enable the kind of syntax you posted here, which can, at times, be convenient. It's called the Method Chaining pattern.
 
Joanne Neal
Rancher
Pie
Posts: 3742
16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greg Charles wrote:Whatever "doc" may be, the addElement() method returns "this", that is a reference to the doc object itself.


Not necessarily. addElement could return an instance of any class that has an addElement(String) method.
Without knowing the type of 'doc', you can't say what addElement returns.
 
cchetan jain
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
firstly doc is in object.after applying the method addElement() on it .it returns an object(may be it is object of the type of doc)..on which by chaining rule again the addElement()method is applied..and now it adds 'something' to it..clear or not??
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic