File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "ElementType.TYPE versus ElementType.FIELD" Watch "ElementType.TYPE versus ElementType.FIELD" New topic

ElementType.TYPE versus ElementType.FIELD

Sudarshan Sreenivasan
Ranch Hand

Joined: Jun 28, 2007
Posts: 188

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 )
[ 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%)
Don't get me started about those stupid light bulbs.
subject: ElementType.TYPE versus ElementType.FIELD
It's not a secret anymore!