2017-02-07 4 views
1
나는 두 가지 방법

수 없습니다

public class Question { 

    @AnnotationA(value = { @AnnotationB(message = "One"), @AnnotationB(message = "Two") }) 
    public int methodOne() { 
     return 1; 
    } 

    @AnnotationA(value = { @AnnotationB(message = "One"), @AnnotationB(message = "Two") }) 
    public int methodTwo() { 
     return 2; 
    } 
} 

내가

public class Question { 

    @AnnotationA(value = annoArray) 
    public int methodOne() { 
     return 1; 
    } 

    @AnnotationA(value = annoArray) 
    public int methodTwo() { 
     return 2; 
    } 

    public AnnotationB[] annoArray = { @AnnotationB(message = "One"), @AnnotationB(message = "Two") } 
} 

을 쓸 수 있도록하고 싶습니다하지만 난의 위치에 Annotations are not allowed here 것을 IntelliJ에 의해 통보하고에 주석을

annoArray.

다른 방법이 있습니까?

답변

1

주석을 컴파일시 상수로 사용해야하기 때문에 불가능합니다. 그러나 최소한 두 가지 가능성이 있습니다.

  1. AnnoationB 값에 대한 상수를 만들 수 있습니다.
  2. AnnotationB에만 문자열이 들어 있고 AnnotationA의 값 구성원을 String []으로 정의 할 수있는 경우 (여기에서 상수를 정의 할 수도 있음)