In StringBuilder class I can do like this:
StringBuilder sb = new StringBuilder();
sb.append( "asd").append(34);
method append returns StringBuilder instance, and I can continuosly call that.
My question is it possible to do so in static method context? without class instance
Yes. Like this (untested).
public class Static {
private final static Static INSTANCE = new Static();
public static Static doStuff(...) {
...;
return INSTANCE;
}
public static Static doOtherStuff() {
....
return INSTANCE;
}
}
You can now have code like.
Static.doStuff(...).doOtherStuff(...).doStuff(...);
I would recommend against it though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With