ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 어노테이션(어트리뷰트?)
    프로그래밍 언어/클래스 2015. 9. 6. 22:55

    메타데이터


    - 자바

    Java 5

    시스템 설정과 관련된 부가적인 사항들은 @에게 위임하고 개발자는 비즈니스 로직 구현에 집중할 수 있다

    리플렉션은 실행중인 자바 클래스의 정보를 볼 수 있게 하고, 그 클래스의 구성 정보로 기능을 수행할 수 있도록 한다


    package c.annotation;

    import java.lang.annotation.ElementType;

    import java.lang.annotation.Retention;

    import java.lang.annotation.RetentionPolicy;

    import java.lang.annotation.Target;

    @Target(ElementType.METHOD)

    @Retention(RetentionPolicy.RUNTIME)

    public @interface UserAnnotation {

    public int number();

    public String text() default "This is first annotation";

    }


    package c.annotation;

    import java.lang.reflect.Method;

    public class UserAnnotationSample {

    @UserAnnotation(number = 1)

    public void annotationSample1() { ... }

    @UserAnnotation(number = 2, text = "second")

    public void annotationSample2() { ... }

    @UserAnnotation(number = 3, text = "third")

    public static void annotationSample3() { ... }

    public void checkAnnotations(Class useClass) {

    Method[] methods = useClass.getDeclaredMethods();

    for (Method tempMethod : methods) {

    UserAnnotation annotation = tempMethod.getAnnotation(UserAnnotation.class);

    if (annotation != null) {

    ... annotation.number() ... annotation.text() ...

    }

    }

    }

    }


    C:\basicjava>javac c/annotation/UserAnnotationSample.java

    C:\basicjava>java c/annotation/UserAnnotationSample


    > 미리 정해져 있는 어노테이션

    @Override

    @Deprecated

    @SuppressWarnings

    {"deprecation"|"unchecked"|}


    - C#

    어트리뷰트



    참조 사이트:

    http://jjjryu.tistory.com/entry/RTTIRun-Time-Type-Information


Designed by Tistory.