• 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
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

Query regarding Java Annotation

 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi I'm new to Java Annotation.

I have gone through some resource on Java Annotation.
they explanied that Anootation type declaratrion is like interface declaration.

e.g.

public @interface RequestForEnhancement {
int id();
String synopsis();
String engineer() default "[unassigned]";
String date(); default "[unimplemented]";
}


but i would like to know that if above annotation declaration is only applicable if you are declaring that on an Interface (e.g. RequestForEnhancement in this case).. Is my understanding is rihgt?

Thanks in Advance.
 
Sheriff
Posts: 22907
132
Eclipse IDE Spring TypeScript Quarkus Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
RequestForEnhancement is not an interface, it's the annotation itself. And you can use it on any package, annotation, class, interface, constructor, method, field, parameter or even local variables, until you specify differently using the annotation Target. For example:


Sun decided not to use a new keyword for annotations (possibly to not break old code that uses annotation as variable names), but instead use @interface for that. It can be a bit confusing at first, but once you remember what the extra @ means there shouldn't be much problems.
 
Jay Shukla
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rob!!!
For your valuable inputs.
 
reply
    Bookmark Topic Watch Topic
  • New Topic