Framework-wide fluent setters?


Has there been any considerations regarding making all setters fluent (return this;)? Returning void in java is a bit of a waste since you don’t have to do any assignments.

in a grid setup I can do

  getColumn("info").setHeaderCaption(i18n("")).setExpandRatio(3).setSortable(false).setEditorField(new TextArea());

but if I want to set the null representation of the editor, I can no longer use

  getColumn("info").setHeaderCaption(i18n("")).setExpandRatio(3).setSortable(false).setEditorField(new TextArea().setNullRepresentation(""));

The feature was considered for Vaadin 7 but dropped as nobody could figure out how to deal with inheritance properly. For instance AbstractComponent has a setter for “caption”, which then would return AbstractComponent. Then you wouldn’t be able to do

new Button().setCaption("Hello").addClickListener(...) as AbstractComponent does not contain “addClickListener”, which is quite strange as you would be able to do it the other way around

new Button().addClickListener(...).setCaption("Hello")