This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Query regarding Java Annotation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Query regarding Java Annotation" Watch "Query regarding Java Annotation" New topic
Author

Query regarding Java Annotation

Jay Shukla
Ranch Hand

Joined: Jun 08, 2008
Posts: 214
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.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jay Shukla
Ranch Hand

Joined: Jun 08, 2008
Posts: 214
Thanks Rob!!!
For your valuable inputs.
 
wood burning stoves
 
subject: Query regarding Java Annotation
 
Similar Threads
Custom runtime annotation processor
Annotations in Java5
Custom Annotation :: inject object at runtime
annotating annotations
Use of annotations..