Annotation Type
Annotation Type
Annotation Type 생성

예제 - 사용할 Annotation 클래스
예제 - 생성한 Annotation type의 적용
Last updated

Last updated
public @interface 이름 {
}package com.hacademy.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface TestEntity {
String author() default "";
String date() default "N/A";
String comment() default "";
}//class, interface, enum에 설정 가능하다
@Target(ElementType.TYPE)
//런타임 시점까지 유지되어 Reflection 등의 코드에서 불러올 수 있다
@Retention(RetentionPolicy.RUNTIME)String author() default "";
String date() default "N/A";
String comment() default "";package com.hacademy.annotation;
@TestEntity(author = "hacademy", date = "2022-03-03", comment = "테스트를 위한 Annotation")
public class Item {
private String name;
private int price;
public void setName(String name) {
this.name = name;
}
public void setPrice(int price) {
this.price = price;
}
public String getName() {
return name;
}
public int getPrice() {
return price;
}
@Override
public String toString() {
return "Item [name=" + name + ", price=" + price + "]";
}
}@Test(value="hello")@Test("hello")