pvgoddijn
pvgoddijn

Reputation: 12898

create a cell for a java.lang.Object

Im trying to add data to a excel sheet with Apache POI but at compile time i dont know what type the actual data objects are which im trying to add to the sheet.

Is there some nice way to just do someThing like

Object obj= someObject;
cell.setValue(obj);

without doing the boilerplate of if/else and instanceof calls to determine whether obj is boolean, date, string, or numeric.

If the object is neither of these types i would expect Obj.toString(); to end up in the cell.

Upvotes: 0

Views: 556

Answers (1)

jzd
jzd

Reputation: 23629

Instead of boilerplate if/else, can't you just overload your method parameters so that you have one method call for each case.

Upvotes: 1

Related Questions