Best practice for use constants in scala annotations

后端 未结 2 1226
长发绾君心
长发绾君心 2021-02-07 05:27

I use tapestry 5 as my choice of web framework. Tapestry allows me to define symbols in the configure class and inject symbols into other components.

for example,

相关标签:
2条回答
  • 2021-02-07 05:38

    The 'final' keyword is required to make the compiler emit it as you would do it in Java. E.g.,

    object Foo
    {
       final val MY_SYMBOLIC_CONSTANT="whatever"
    }
    

    It seems that, otherwise, you only get an accessor method under the hood which is not statically calculable.

    0 讨论(0)
  • 2021-02-07 05:52

    It doesn't seem possible w/ scala versions 2.8.1.final, 2.8.2.final, or 2.9.1.final (the result was the same with all):

    object Constant { val UNCHECKED = "unchecked" }
    
    class Test {                                       
        @SuppressWarnings(Array(Constant.UNCHECKED))   
        def test: Unit = println("testing.. 1, 2... 3")
    }
    

    .

    <console>:7: error: annotation argument needs to be a constant; found: Constant.UNCHECKED
               @SuppressWarnings(Array(Constant.UNCHECKED))
    
    0 讨论(0)
提交回复
热议问题