Bug 53625 - setters should return "this" rather than void
Summary: setters should return "this" rather than void
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: POI Overall (show other bugs)
Version: 3.8-FINAL
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-30 19:58 UTC by Scott Dunbar
Modified: 2012-08-12 10:20 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Scott Dunbar 2012-07-30 19:58:12 UTC
This is more of a change request than a bug.

It would be nice if setters across the board could return "this".  By changing the code this way instead of doing:

Cell myCell = row.createCell();
myCell.setCellStyle( myStyle );
RichTextString rts = createHelper.createRichTextString( "hello );
rts.applyFont( boldFont );
myCell.setCellFont( rts );

I could do:

Cell myCell = row.createCell()
                 .setCellStyle( myStyle )
                 .setCellFont( createHelper.createRichTextString( "hello" )
                               .applyFont( boldFont ) );

The previous code would continue to work but if you prefer a more compact version with fewer intermediate variables a change from void setters would allow this.
Comment 1 Yegor Kozlov 2012-08-12 10:20:02 UTC
Unfortunately we cannot change setters to return "this" becasue POI must be binary-compatible wuth existing code.
 
If we make this change then the old code would work ONLY if you re-compile it against the latest build of POI.
If you simply change the return type and replace the POI jar then Java will not be able to find the new methods and throw NoSuchMethodError.

Yegor