Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala _Scala - Fatal编程技术网

Scala

Scala ,scala,Scala,正如许多人已经知道的那样,Scala XML文本允许以一种简单的方式将XML文本嵌入到代码中。通过使用{}符号,可以嵌入变量信息 例如: val something = "SOMETHING" val xml = <elem>{hello}</elem> 我的问题是,如何在注释中嵌入变量信息 这不起作用: val xml = <elem><!-- A comment with {something} variable--></elem>

正如许多人已经知道的那样,Scala XML文本允许以一种简单的方式将XML文本嵌入到代码中。通过使用{}符号,可以嵌入变量信息

例如:

val something = "SOMETHING"
val xml = <elem>{hello}</elem>
我的问题是,如何在注释中嵌入变量信息

这不起作用:

val xml = <elem><!-- A comment with {something} variable--></elem>
您可以使用Scala的注释案例类

import scala.xml.Comment

val comment = Comment("A comment with " + something + " variable")
val xml = <elem>{comment}</elem>
这将打印出:

<elem><!-- A comment with SOMETHING variable--></elem>
查看文档

您可以使用Scala的Comment case类

import scala.xml.Comment

val comment = Comment("A comment with " + something + " variable")
val xml = <elem>{comment}</elem>
这将打印出:

<elem><!-- A comment with SOMETHING variable--></elem>
查看文档

更加紧凑:val xml={CommentsA comment with$something variable}更加紧凑:val xml={CommentsA comment with$something variable}