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
This is called method-chaining.
To do it, you always need an instantiated object. So, sorry, but you cannot do it in a static context as there is no object associated with that.
You want the builder pattern on a static? No. Best to convert your statics to instances.
Do you want this ?
maybe I don't understand the question (static context) correctly
do you mean this?
static {
} //of course you can do this, too
if not all above, you can't do without any static method because append() is not static
As said here You can simply return
null
. For example:Yes. Like this (untested).
You can now have code like.
I would recommend against it though.