【发布时间】:2011-02-10 22:04:37
【问题描述】:
以下代码(复制自 a question from about a year ago)在 Scala 2.7.7 下运行良好,但在 Scala 2.8.0(Beta 1,RC8)下无法正常运行。
import scala.xml
class Person(name : String, age : Int) {
def toXml(): xml.Elem =
<person><name>{ name }</name><age>{ age }</age></person>
}
def peopleToXml(people: Array[Person]): xml.Elem = {
<people>{ for {person <- people} yield person.toXml }</people>
}
val data = Array(new Person("joe",40), new Person("mary", 35))
println(peopleToXml(data))
输出(根据 2.7.7)应该是:
<people><person><name>joe</name><age>40</age></person><person><name>mary</name><age>35</age></person></people>
但结果却是:
<people>\[Lscala.xml.Elem;@17821782</people>
如何让它像在 2.7.x 中一样运行?
【问题讨论】: