可以在scala中命名常量?
发布时间:2020-12-16 18:51:52 所属栏目:安全 来源:网络整理
导读:看起来注释需要 Java中的常量.我想这样做: object ConfigStatics { final val componentsToScan = Array("com.example")}@PropertySource( ConfigStatics.componentsToScan ) // error: constant value requiredclass MyConfig extends WebMvcConfigurerAda
看起来注释需要
Java中的常量.我想这样做:
object ConfigStatics { final val componentsToScan = Array("com.example") } @PropertySource( ConfigStatics.componentsToScan ) // error: constant value required class MyConfig extends WebMvcConfigurerAdapter { } 哪里 @PropertySource( Array("com.example") ) class MyConfig extends WebMvcConfigurerAdapter { } 很好. 遗憾的是,scala不会将静态最终值视为常量值. 这里有什么可做的,或者它是不可能在scala中有命名常量? 解决方法
这看起来像一个bug.
SLS 6.24表示文字数组Array(c1,c2,…)是一个常量表达式. SLS 4.1表示常量值定义最终val x = e表示x由e代替. 它不会那样工作,所以要么是规范错误,要么是实现错误. final val j = Array(1,2,3) def k = j // j final val x = 3 def y = x // 3 这是this question的副本,其中反义词承诺打开一张关于它的票. 那是三年前.我想知道他的终端上是否还有一个黄色的贴子? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |