gpt4 book ai didi

scala - 多行注释中的 "error: unclosed comment"

转载 作者:行者123 更新时间:2023-12-01 10:38:39 25 4
gpt4 key购买 nike

将模板从 Java 转换为 Scala 时,我注意到以下带有多行注释的怪癖可以简化为以下代码段:

/**
* /*
*/

class Blah {}

上面的代码无法编译并显示“错误:未关闭的注释”,但在 Java 中有效。

这被证明是有问题的,因为它使记录例如接受 glob 类型的字符串(例如“需要类似 something/*.myformat 的路径”)。

这是错误还是功能?

最佳答案

事实上,它是一项功能。引用Section 1.4 of the Scala Language Specification :

A multi-line comment is a sequence of characters between /* and */. Multi-line comments may be nested, but are required to be properly nested. Therefore, a comment like /* /* */ will be rejected as having an unterminated comment.

(强调我的)

幸运的是,在您需要它的情况下变通相对容易(例如问题中的 glob 示例)by escaping the / or * literal , 像这样的网:

/**
* /*
*/

在生成的 Scaladoc 中正确显示。

关于scala - 多行注释中的 "error: unclosed comment",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31741492/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com