Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Annotations Writing Your Own Annotation Declaring an Annotation

Tornike Shelia
Tornike Shelia
2,781 Points

In LiveTweet.java below, declare an annotation named LiveTweet. This could hypothetically be used to send a Tweet every

LiveTweet.java

@LiveTweet

I don't get it , whats the problem ?

1 Answer

Alex Bratkovskij
Alex Bratkovskij
5,329 Points

Hi, the issue is that you're not declaring annotation but simply using it. Before using annotations, you need to create it. Annotations are kinda like methods, but it doesn't affect your code, it affects the compiler, or just holds valuable info. To declare annotation you need to use @interface:

@interface LiveTweet{
       //here goes your code
}

More ingo on annotations: https://docs.oracle.com/javase/tutorial/java/annotations/

How to declare them: https://docs.oracle.com/javase/tutorial/java/annotations/declaring.html