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

In LiveTweet.java below, declare an annotation named LiveTweet.

Hoping someone can help me with this challenge. I really don't understand what it's trying to get me to do.

1 Answer

Daniel Vargas
Daniel Vargas
29,184 Points

You just have to do the exact same thing Chris did in the video, if you want to declare an annotation you should use @interface:

public @interface theNameOfYourAnnotation {

}

In the second part they just ask you to annotate your new annotation using @Retention(RetentionPolicy.RUNTIME). Just put that above of your annotation:

@Retention(RetentionPolicy.RUNTIME)
public @interface theNameOfYourAnnotation {

}

Remember you should also import Retention and RetentionPolicy

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

I tried to answer you without directly giving you the answer, however is not that far away. I hope I was able to be clear.

Hey Daniel, thanks a lot.

I guess I was just really over thinking it and confusing myself. I didn't realize I was supposed to use the @Interface. I thought somehow I was supposed to create a new annotation as @LiveTweet. Once I saw that's what I was supposed to do, it was all very clear.

Thanks again!