Skip to content

Commit 44fd86d

Browse files
committed
Update "Java built-in Annotations" article
1 parent 914b575 commit 44fd86d

3 files changed

Lines changed: 38 additions & 0 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.baeldung.annotations;
2+
3+
import javax.annotation.Generated;
4+
5+
@RetentionAnnotation
6+
@Generated("Avilable only on source code")
7+
public class AnnotatedClass {
8+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.baeldung.annotations;
2+
3+
import java.lang.annotation.Retention;
4+
import java.lang.annotation.RetentionPolicy;
5+
import java.lang.annotation.Target;
6+
7+
import static java.lang.annotation.ElementType.TYPE;
8+
9+
@Target(TYPE)
10+
@Retention(RetentionPolicy.RUNTIME)
11+
public @interface RetentionAnnotation {
12+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.baeldung.annotations;
2+
3+
import org.junit.Test;
4+
5+
import java.lang.annotation.Annotation;
6+
7+
import static org.hamcrest.core.Is.is;
8+
import static org.junit.Assert.assertThat;
9+
10+
public class AnnotatedClassUnitTest {
11+
12+
@Test
13+
public void whenAnnotationRetentionPolicyRuntime_shouldAccess() {
14+
AnnotatedClass anAnnotatedClass = new AnnotatedClass();
15+
Annotation[] annotations = anAnnotatedClass.getClass().getAnnotations();
16+
assertThat(annotations.length, is(1));
17+
}
18+
}

0 commit comments

Comments
 (0)