Must annotations, such as  @SampleAnnotation, be attached only to (placed before) a class declaration? Can we use the @SampleAnnotation tag just before a method we want to apply it to?
            Asked
            
        
        
            Active
            
        
            Viewed 160 times
        
    0
            
            
        - 
                    1Consider the standard [`@Override`](http://stackoverflow.com/questions/94361/when-do-you-use-javas-override-annotation-and-why) annotation, for an example that *only* makes sense when applied to a method. – Raedwald Jul 28 '14 at 11:54
1 Answers
1
            That depends on the annotation. Theses are the possible locations for an annotiation (from javadoc @Target:
> ANNOTATION_TYPE Annotation type declaration 
> CONSTRUCTOR Constructor declaration 
> FIELD Field declaration (includes enum constants)
> LOCAL_VARIABLE Local variable declaration METHOD Method declaration
> PACKAGE Package declaration 
> PARAMETER Parameter declaration 
> TYPE Class, interface (including annotation type), or enum declaration
 
    
    
        BetaRide
        
- 16,207
- 29
- 99
- 177
- 
                    Thhanks for your quick response..... The actual problem is that I want to add an annotation(having 3 fields) to a method and then, get some value, say 'a', from a private variable and then assign the value of that variable 'a' to an element of an annotation.... but I am unable to do it unless i add an annotation to the class.... Do you have any idea how this could be done? – Prateek Jul 28 '14 at 12:10
 
    