Esquire Theme by Matthew Buchanan
Social icons by Tim van Damme

01

Jul

Did not know about java.lang.Appendable

Don’t you hate when you find or learn something that could have saved you some time or perhaps enabled a better design.

Well java.lang.Appendable is an interface that I somehow completely missed. There are many times I have wanted to accept StringBuilder/StringBuffer/Writer as an argument and I always end up using a Writer as the generic object.

For JATL I ended up using a java.io.Writer as the output conduit. Now I know that was a mistake so look for JATL 1.0 to use Appendable instead of Writer.

The only annoying thing about Appendable is that it throws an IOException which is annoying if you are used to StringBuilder and StringBuffer which do not (both implement the interface but do not throw the exception … a nice example of Java’s Covariance).

To work around this annoyance I have written an aspect that will soften the IOException so that it any appendable is just like using StringBuilder: