2

I use an annotation with complex parameters frequently, e.g.:

@CookieValue(value = SomeClass.SOME_STATIC_FIELD, required = false) UUID cookieValue

Is it possible to define a new name for this annotation, so the above could be replaced like this?

@MyCookieValue UUID cookieValue

I tried the following, based on this: How to extend Java annotation? Unfortunately, the syntax is not correct.

@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface MyCookieValue {
    CookieValue cookieValue(value = SomeClass.SOME_STATIC_FIELD, required = false);
}
nagy.zsolt.hun
  • 6,292
  • 12
  • 56
  • 95
  • Have you tried this: `@Target(ElementType.PARAMETER) @Retention(RetentionPolicy.RUNTIME) @CookieValue(value = SomeClass.SOME_STATIC_FIELD, required = false) public @interface MyCookieValue { }` ? – Lorelorelore Mar 28 '19 at 14:58
  • It shows the error message: `The annotation @CookieValue is disallowed for this location`. Spring `@CookieValue` is only applicable on parameters. – nagy.zsolt.hun Mar 28 '19 at 15:04

0 Answers0