2014-06-17 5 views
0

주석 유형과 주석 자체의 실제 차이점은 무엇입니까? 내 선생님이이 두 가지가 다르다는 것을 그가 말했기 때문에이 문제를 해결하라고 말했습니다.주석 유형 대 주석 (Java)

누군가 나에게 설명해 줄 수 있습니까? 나는 그것을 인터넷에서 찾았지만 아무 것도 발견하지 못했다. 정말 사과했습니다.

감사합니다. :)

@Target(value = ElementType.METHOD) 
@Retention(value = RetentionPolicy.RUNTIME) 
public @interface DBoperation { 

    public enum ParamType { 
     FLOAT, INT, DOUBLE, CHAR, BOOLEAN, LONG, SHORT, BYTE, REFERENCE, NONE 
    } 

    public enum OperationType { 
     CONNECT, DISCONNECT, UPDATE, QUERY, DELETE 
    } 

    public OperationType typOp() default OperationType.QUERY; 
    public ParamType typParam() default ParamType.REFERENCE; 
    String description();  
} 
+2

클래스와 개체의 차이점은 무엇입니까? – shmosel

+0

혼란의 징후에 대한 예를 들어 줄 수 있습니까? 코드에서 제발? 이 질문은 약간 불분명하다. –

+0

세 가지 메소드로 인터페이스를 구현하고 있고 모든 메소드에'@ Override'를 넣으면 세 개의 주석이 있습니다. 그것들은 모두 동일한 주석 유형 [[java.lang.Override'] (http://docs.oracle.com/javase/8/docs/api/java/lang/Override.html)을 참조합니다. JLS의 9.6 및 9.7 절 ([http://docs.oracle.com/javase/specs/jls/se8/html/jls-9.html#jls-9.6])을 참조하십시오. – ajb

답변

0

코드 샘플은 주석 유형의 선언입니다. 주석을 사용하여 주석을 추가하는 모든 방법에는 주석의 데이터가 포함 된 주석이 있습니다.

리플렉션을 사용하여 주석을 얻을 수 있습니다 (예 : 이렇게 :

Class<?> annotatedClass = // put some class here 
int methodIndex = // index of a annotated method 
// get the annotation 
// dbOperation is the annotation, DBoperation the type 
DBoperation dbOperation = annotatedClass.getMethods()[methodIndex].getAnnotation(DBoperation.class); 

// get data from the annotation 
String operationDescription = dbOperation.description();