加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – 字母数字标识符和’$’字符

发布时间:2020-12-16 18:07:45 所属栏目:安全 来源:网络整理
导读:从 Scala中的编程6.10(页151): Identifiers in user programs should not contain ‘$’ character,even though it will compile; if they do this might lead to name clashes with identifiers generated by Scala compiler. 我确信这是一个原因,但为什么
从 Scala中的编程6.10(页151):

Identifiers in user programs should not contain ‘$’ character,even though it will compile; if they do this might lead to name clashes with identifiers generated by Scala compiler.

我确信这是一个原因,但为什么不阻止在字母数字标识符中使用’$’字符呢?

解决方法

Scala编译器内部生成的一些标识符包含’$’字符.如果使用“$”字符创建新标识符,则可能会与内部生成的字符发生冲突,然后出现混乱. OTOH,你有时需要’$’字符,要么在那些(现在非常罕见的)场合需要访问内部生成的Scala字符,要么是因为有人在你希望调用的 Java代码中使用了这样的标识符(它是合法的,如果也气馁).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读