如何创建一个类型,它是 aMarkupBuilder
但具有用 a 初始化的默认构造函数StringWriter
并覆盖以toString()
调用?toString()
StringWriter
思路如下,当然不允许在调用超级构造函数之前初始化实例变量:
class StringWriterMarkupBuilder extends MarkupBuilder {
final def sw = new StringWriter()
StringWriterMarkupBuilder() {
super(sw)
}
@Override String toString() {
sw.toString()
}
}