File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Strange code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Strange code" Watch "Strange code" New topic
Author

Strange code

Nick Petas
Ranch Hand

Joined: Jan 31, 2007
Posts: 38
I stumbled uppon this code :



Is it valid code and what exactly does it do?
Thank you.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

What exactly do you find strange about it?

You can write it on one line:


It does the same as this:

As you know, you use the "." syntax to call a method on an object: variable name, dot, method name, parentheses, semi-colon. If the method returns something, you can assign the return value to a variable. Then on that variable you can again call a method.

You can also do this in one go. So, for example the expression new ClassName(this) gives you a ClassName object; you don't need to assign that to a variable first, you can directly call a method on it by putting a "." and the method name after it: new ClassName(this).setMethod1();. And the method call in turn can return an object, on which you can again call a method directly. So you can chain multiple method calls like that.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Nick Petas
Ranch Hand

Joined: Jan 31, 2007
Posts: 38
Oh yes of course.
Now I get it.
Thanks a lot for the rapid answer!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Strange code
 
Similar Threads
onload
input type=file
Netscape7.1 and window.createPopup()
build.xml question
Why we live?