How to do method chaining in Java? o.m1().m2().m3().m4()

Posted by Pentium10 on Stack Overflow See other posts from Stack Overflow or by Pentium10
Published on 2010-05-20T08:52:32Z Indexed on 2010/05/20 9:00 UTC
Read the original article Hit count: 198

Filed under:
|

Maybe the title might be better, if someone knows a better one, please edit.

I've seen in many Java code notation that after a method we call another, here is an example.

Toast.makeText(text).setGravity(Gravity.TOP, 0, 0).setView(layout).show();

As you see after calling makeText on the return we call setGravity and so far.

How can I do this with my own classes? Do I have to do anything special?

© Stack Overflow or respective owner

Related posts about java

Related posts about breadcrumbs