How can I make a type which is a MarkupBuilder but has default constructor which is initialized with a StringWriter and overrides toString() to call the toString() on the StringWriter?
The idea is like the following, but of course initializing instance variables before super constructor calls is not allowed:
class StringWriterMarkupBuilder extends MarkupBuilder {
final def sw = new StringWriter()
StringWriterMarkupBuilder() {
super(sw)
}
@Override String toString() {
sw.toString()
}
}
You could also do this with the
metaClasslike so: