Note that there are some explanatory texts on larger screens.

plurals
  1. POScala constant expressions and computed string literals
    primarykey
    data
    text
    <p>I'm running into some trickiness with Java annotations and the stipulation that their arguments must be "constants". 6.24 of the Scala 2.8 Language Specification states that "constant expressions" are any of the following (emphasis mine):</p> <ul> <li>A literal of a value class, such as an integer</li> <li><em>A string literal</em></li> <li>A class constructed with Predef.classOf (§12.5)</li> <li>An element of an enumeration from the underlying platform</li> <li>A literal array, of the form Array(c1, ..., cn), where all of the ci’s are themselves constant expressions</li> <li>An identifier defined by a constant value definition (§4.1).</li> </ul> <p>Now, a "string literal" seems to be defined in such a way that it's really just one " " or """ """ delimited block of characters, which is pretty clear-cut. My question, then, is why given</p> <pre><code>object MyObject { final val MY_CONSTANT1="foo" final val MY_CONSTANT2="bar" + "baz" final val MY_CONSTANT3="qux" + "quux" + "frobozz" } // ... @MyAnnotation( ??? ) def Foo(): Unit { ... </code></pre> <p><code>@MyAnnotation</code> compiles and scaladocs with MY_CONSTANT1 and MY_CONSTANT2, but not MY_CONSTANT3 (I get "annotation argument needs to be a constant"). Why does MY_CONSTANT2 work at all? Is there some unspecified at-most-two-string-literals-can-combine-to-become-a-larger-one rule at work, or am I insane?</p> <p><em>edit</em> I'm using Scala 2.10, which seems to have fixed some annotation-related compiler errors from earlier Scala versions.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload