File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I can't use meta-annotations.

 
Andrew Stallard
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we see the source code that generates the error?
 
Andrew Stallard
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 152
Linux VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Did you import the annotation?

Henry
 
Matt Cartwright
Ranch Hand
Posts: 152
Linux VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry Henry, did it again
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are annotations used very much in actual programming practice? They seem to me to be just an easy way to make mistakes.
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 :-)
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic