My team mates introduce me to new practice writing method which will not return void.
public class Test {
public Test doCalculations() {
//code
return this;
}
public Test appendTitle(String test) {
//code
return this;
}
}
Instead of returning void they suggest to return object itself. One of the advantage of this aproach they say, you can chain methods.
Instead of writing:
while(1) {
test.appendTitle("aaa");
test.doCalculations();
map.add(test);
}
You can write more elegant code:
while(1) {
map.add(test.appendTitle("aaa").doCalculations());
}
What could be disadvantages of this aproach? Do you suggest to include it in daily use?