wood burning stoves*
The moose likes Java in General and the fly likes I can't use meta-annotations. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "I can Watch "I can New topic
Author

I can't use meta-annotations.

Andrew Stallard
Ranch Hand

Joined: Mar 06, 2010
Posts: 33
Hello, my compiler can't seem to recognize the meta-annotations:

@Target
@Documented
@Inherited
@Retention

When attempting to compile, I keep getting an error like this:

TestTarget.java:1: cannot find symbol
symbol: class Target
@Target(ElementType.METHOD)

This happens whether I do or don't use an IDE.



David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Can we see the source code that generates the error?
Andrew Stallard
Ranch Hand

Joined: Mar 06, 2010
Posts: 33
David Newton wrote:Can we see the source code that generates the error?


@Target(ElementType.METHOD)
public @interface TestTarget{
public String doTestTarget();
}
Here it is
Matt Cartwright
Ranch Hand

Joined: Aug 25, 2008
Posts: 149

you are missing two imports,
and please use the code tag next time you post code

Try this:


Hope that helps
M
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18532
    
  40


Did you import the annotation?

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Matt Cartwright
Ranch Hand

Joined: Aug 25, 2008
Posts: 149

sorry Henry, did it again
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18532
    
  40

Matt Cartwright wrote:sorry Henry, did it again


2 minutes, I am okay with.... I am still irked with 8 seconds...

Henry
Andrew Stallard
Ranch Hand

Joined: Mar 06, 2010
Posts: 33
Henry Wong wrote:
Did you import the annotation?

Henry


No, I didn't. I am now headed to the corner to affix my dunce cap.

Andrew Stallard
Ranch Hand

Joined: Mar 06, 2010
Posts: 33
Are annotations used very much in actual programming practice? They seem to me to be just an easy way to make mistakes.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41120
    
  45
Annotations were introduced in Java 5, so they haven't been around that long, but these days they're becoming quite common. Many APIs use annotations extensively, so there's really no way of avoiding them completely. If nothing else, you should get in the habit of using the @Override annotation, the preventor of truly silly bugs.

By the way, when you say "an easy way to make mistakes", I hope that's based on more than this one issue :-)


Ping & DNS - my free Android networking tools app
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Andrew Stallard wrote:Are annotations used very much in actual programming practice? They seem to me to be just an easy way to make mistakes.

Absolutely; they're used all over the place, for many different reasons. How is it any easier to make mistakes with annotations?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I can't use meta-annotations.
 
Similar Threads
Finding annotations from subclass or child class
getter and setter generation with annotations
About Annotations
what is the use of interface which has no methods?
Metadata