Update "Java built-in Annotations" article

This commit is contained in:
Ali Dehghani 2021-02-19 17:01:58 +03:30
parent 07eab8386c
commit e5b7e9c81f
3 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,8 @@
package com.baeldung.annotations;
import javax.annotation.Generated;
@RetentionAnnotation
@Generated("Avilable only on source code")
public class AnnotatedClass {
}

View File

@ -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 {
}

View File

@ -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));
}
}