[jdom-interest] Another suggestion for the Element class

Elliotte Rusty Harold elharo at metalab.unc.edu
Wed Nov 15 06:13:30 PST 2000


At 2:02 AM -0800 11/14/00, Jason Hunter wrote:
>>  Having to use String.valueOf repeatedly can be tedious (although it is
>>  certainly workable).  My recommendation would be to add some
>>  convenience
>>  methods to handle conversion of primitive types into Strings:
>>
>>      public Element setText(int iTextValue);
>>      public Element setText(long lTextValue);
>>      ...
>>
>>  The method bodies would follow this format:
>>      public Element setText(int iTextValue) {
>>          return setText(String.valueOf(iTextValue));
>>      }
>>
>>  This would allow quick conversion of primitive types without requiring
>>  the programmer to do the String conversions manually every time.
>>  Comments?

I would prefer not to clutter the API with these extra methods. 
Smaller APIs are more beautiful, IMHO. As you point out, doing 
without them is trivial. If you really find you need them, then it's 
straight-forward to write a subclass of Element that provides them 
that you can use in your own code and the rest of us can be 
blissfully ignorant of.
-- 

+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
|                  The XML Bible (IDG Books, 1999)                   |
|              http://metalab.unc.edu/xml/books/bible/               |
|   http://www.amazon.com/exec/obidos/ISBN=0764532367/cafeaulaitA/   |
+----------------------------------+---------------------------------+
|  Read Cafe au Lait for Java News:  http://metalab.unc.edu/javafaq/ |
|  Read Cafe con Leche for XML News: http://metalab.unc.edu/xml/     |
+----------------------------------+---------------------------------+



More information about the jdom-interest mailing list