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 trialWei Han Liu
11,231 PointsAdding elements to custom annotation in Java
I don't understand the question and the method to solve this. Can anybody help me?
Add two elements to the LiveTweet annotation:
- username, declared as a String. Set its default to an empty String.
- hashtags, declared as a String array. Set its default to an empty array.
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
@Target({ElementType.TYPE,ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface LiveTweet {
String desc() default "";
String[] params() default {};
}
2 Answers
Fahad Mutair
10,359 Pointschange your element names to username and your array name to hashtags
Sagar Thakkar
8,814 Pointsimport java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
@Target({ElementType.TYPE,ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface LiveTweet {
String username() default "";
String[] hashtags() default {};
}