0

以下のように、ゲッターにいくつかの注釈があります。同じクラスのブール値に基づくゲッターでのすべてのアノテーション呼び出しをスキップしたいと思います。それを行う方法はありますか?

@MyAnnotation1(message = "{someMessage1}")
@MyAnnotation2(message = "{someMessage2}")
public Date getFromDate() {
    return fromDate;
}
4

1 に答える 1

0

@Ignoreその注釈付きフィールドが設定されている場合は、そのフィールド上に別の注釈を定義できます。注釈処理は無視してかまいません。

   @Ignore
   private boolean value;

独自の注釈を次のように定義できます

   @Target(ElementType.FIELD)
   @Retention(RetentionPolicy.RUNTIME)
   /**
    * This Annotation should be used on boolean field to set specify whether annotation processing should be        ignored for that class
    */
   public @interface Ignore {

   }

これはカスタムアノテーションであるため、処理するコードを作成する必要があることを忘れないでください

PS注:カスタムアノテーションを作成していると仮定します。そしてそこに処理があります。

于 2012-10-02T19:06:01.610 に答える