aspose file tools*
The moose likes Beginning Java and the fly likes Annotation question. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Annotation question." Watch "Annotation question." New topic
Author

Annotation question.

Treimin Clark
Ranch Hand

Joined: Nov 12, 2008
Posts: 757
Suppose that "Enumerated" is an annotation, which has only one parameter as below:



In this case, EnumType is a class, which has some final variables like: EnumType.ORDINAL and EnumType.STRING

For sure, we can 'call' to this annotation as below:

@Enumerated(EnumType.ORDINAL) ....


But, how can we use it as below,

@Enumerated(ORDINAL) .....

How does the compiler know that ORDINAL is from EnumType, in that case? Is this really compile-able?

I found this type usages of annotations from many books.

(Currently I have no such environment to test this my self).



Source:
The EJB 3.0 JPA Specification
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

Using static imports you should be able to do what you want.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Treimin Clark
Ranch Hand

Joined: Nov 12, 2008
Posts: 757
Rob Prime wrote:Using static imports you should be able to do what you want.


Yes I know that, but did you mean that we can't access it without using static importing statement?

Thanks Rob,
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

The compiler needs to know where to find it, so you need to:
1) import it
2) use a larger part of the full name*

You can't expect the compiler to check all constants of classes (or all enums), and just pick one if there are multiple matches, now can you?
Treimin Clark
Ranch Hand

Joined: Nov 12, 2008
Posts: 757
Thanks Rob, I asked this question, because I've seen this in many books.

Thanks again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Annotation question.