title: Using String.format() as annotation attribute value
body: <p>I have a class that have a number of constants:</p>
  
  <pre><code>public class SecurityConstants {
      private static final String HAS_ROLE_TEMPLATE = "hasRole('%s')";
  
      public static final String ROLE_USER_INTERNAL = "ROLE_USER_INTERNAL";
      public static final String HAS_ROLE_USER_INTERNAL = String.format(HAS_ROLE_TEMPLATE, ROLE_USER_INTERNAL);
  }
  </code></pre>
  
  <p>If I then try to use <code>HAS_ROLE_USER_INTERNAL</code> as <code>@PreAuthorize</code> annotation attribute value like this <code>@PreAuthorize(SecurityConstants.HAS_ROLE_USER_INTERNAL)</code> compiler fails with:</p>
  
  <blockquote>
    <p>The value for annotation attribute
    PreAuthorize.value must be a constant
    expression</p>
  </blockquote>
  
  <p>However if I change <code>HAS_ROLE_USER_INTERNAL</code> to be a simple <code>String</code> it works just fine:</p>
  
  <pre><code>public static final String HAS_ROLE_USER_INTERNAL = "hasRole('ROLE_USER_INTERNAL')";
  </code></pre>
  
  <p>What's the problem with using <code>String.format()</code>? Field is <code>static</code> and <code>final</code>, what can possibly go wrong?</p>