Update "Java built-in Annotations" article
This commit is contained in:
parent
07eab8386c
commit
e5b7e9c81f
|
@ -0,0 +1,8 @@
|
||||||
|
package com.baeldung.annotations;
|
||||||
|
|
||||||
|
import javax.annotation.Generated;
|
||||||
|
|
||||||
|
@RetentionAnnotation
|
||||||
|
@Generated("Avilable only on source code")
|
||||||
|
public class AnnotatedClass {
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.baeldung.annotations;
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
import static java.lang.annotation.ElementType.TYPE;
|
||||||
|
|
||||||
|
@Target(TYPE)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface RetentionAnnotation {
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.baeldung.annotations;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
|
||||||
|
import static org.hamcrest.core.Is.is;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
public class AnnotatedClassUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenAnnotationRetentionPolicyRuntime_shouldAccess() {
|
||||||
|
AnnotatedClass anAnnotatedClass = new AnnotatedClass();
|
||||||
|
Annotation[] annotations = anAnnotatedClass.getClass().getAnnotations();
|
||||||
|
assertThat(annotations.length, is(1));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue