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 EJB Certification (SCBCD/OCPJBCD) and the fly likes ElementType.TYPE versus ElementType.FIELD 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 » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "ElementType.TYPE versus ElementType.FIELD" Watch "ElementType.TYPE versus ElementType.FIELD" New topic
Author

ElementType.TYPE versus ElementType.FIELD

Sudarshan Sreenivasan
Ranch Hand

Joined: Jun 28, 2007
Posts: 188

Hi,
The below i have borrowed from the following website annotations tutorials

@Target(ElementType.TYPE)�can be applied to any element of a class
@Target(ElementType.FIELD)�can be applied to a field or property


My understanding of the above is such that
A annotation marked with ElementType.TYPE can also be applied to a field in the class

However annotation marked as a ElementType.FIELD cannot be applied to type(Custom defined field) in the class.

Is this correct ??

What exactly is a field or property (explain with an example please)

My understanding of a TYPE is that it should be a class rather than a primitive. (Is this correct )
Thanks
[ September 24, 2008: Message edited by: sid sree ]
Sergio Tridente
Ranch Hand

Joined: Mar 22, 2007
Posts: 329

Accordingly to the javadocs:

ElementType.TYPE: Class, interface (including annotation type), or enum declaration
ElementType.FIELD: Field declaration (inlcudes enum constants)


SCJP 1.4 (88%) - SCJP 5.0 Upgrade (93%) - SCWCD 1.4 (97%) - SCBCD 5.0 (98%)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: ElementType.TYPE versus ElementType.FIELD
 
Similar Threads
Annotations in Java5
Annotations for Enum Constants
Enthuware question com.enthuware.ets.scbcd.v5.2.69
Question on @Resource Annotation
Query regarding Java Annotation