Content deleted Content added
No edit summary |
No edit summary |
||
Line 60:
<syntaxhighlight lang="java">
public class Animal {
public void speak() {}
public String getType() {
Line 86 ⟶ 85:
<syntaxhighlight lang=Java>
}
// Declares the annotation Twizzle.▼
public @interface Twizzle {▼
}
</syntaxhighlight>
Line 99 ⟶ 100:
<syntaxhighlight lang=Java>
</syntaxhighlight>
Line 119 ⟶ 120:
<syntaxhighlight lang=Java>
</syntaxhighlight>
Line 261:
String developer() default "Unknown";
String lastModified();
String
int meaningOfLife();
}
Line 284:
public class UseCustomAnnotation {
public static void main(String
Class<SetCustomAnnotation> classObject = SetCustomAnnotation.class;
readAnnotation(classObject);
Line 291:
static void readAnnotation(AnnotatedElement element) {
try {
System.out.println("Annotation element values:
if (element.isAnnotationPresent(TypeHeader.class)) {
// getAnnotation returns Annotation type
Annotation singleAnnotation = element.getAnnotation(TypeHeader.class);
TypeHeader header = (TypeHeader) singleAnnotation;
System.out.
System.out.
// teamMembers returned as String
System.out.print("Team members: ");
for (String member : header.teamMembers()) {
System.out.
System.out.println();
System.out.println("Meaning of Life: %s%n"
}
} catch (Exception exception) {
|