• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

How to declare aliases for annotation attributes in java?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI, When I am going through the @AliasFor annotation in spring, they have introduced the topic "declare aliases for annotation attributes" ? Can some one explain me what is aliases for attributed?

Below the is code:
@Retention(RetentionPolicy.RUNTIME)
@Target({java.lang.annotation.ElementType.METHOD})
@Documented
public @interface AliasFor
{
 @AliasFor("attribute")
 String value() default "";
 
 @AliasFor("value")
 String attribute() default "";
 
 Class<? extends Annotation> annotation() default Annotation.class;
}
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It just means that the attributes 'value' and 'attribute' are different names for the same thing. This is sometimes convenient. It means that you can write: @Something(value = "hello") or @Something(attribute = "hello") and they mean exactly the same thing.

Note that the attribute named 'value' has special meaning with Java annotations; you can specify the value of the 'value' attribute without actually writing '(value = ...)'; you can just specify the value itself. In other words: @Something("hello") is the same as @Something(value = "hello") and if 'attribute' is an alias for 'value', then this is the same as @Something(attribute = "hello").

Note that the @AliasFor annotation is specific to the Spring framework. It will not work if you are not using the Spring framework.
 
reply
    Bookmark Topic Watch Topic
  • New Topic