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(lay
Adding return this; would surely help in chaining for this class but fail for sub-classes.
If you want to have the chaining behaviour inherited to the sub-classes also then change your class signature as below:
Class SuperClass < SubClass extends SuperClass >{}
This way all sub-classes will inherit method chaining.
Example:
public class SuperClass {
public SubClass testMethod(){
return (SubClass)this;
}
public static void main(String[] args) {
SuperClass superClass = new SuperClass();
superClass.testMethod().testMethod().testMethod();
System.out.println(superClass.toString());
}
}