2017-05-02 15 views
-6

ご覧のとおり、私は3種類の注釈クラスを持っています。クラス名以外の3つはすべて同じです。 Tree.getAnnotations()を呼び出すと表示されるのは、@Elementの注釈だけです。注釈が1つだけ表示されています

@Element(name = "node") 
public class Tree<T> { 

    private Tree<T>[] children = null; 
    private T value; 

    public Tree(T v, Tree<T>[] trees){ 
     children = trees; 
     value = v; 
    } 

    public Tree(T v){ 
     value = v; 
    } 

    @SubElements(name = "subnodes") 
    public Tree<T>[] getChildren(){ 
     return children; 
    } 

    @ElementField(name = "value") 
    public T getValue(){ 
     return value; 
    } 

} 

これは、アノテーションクラスです:

import java.lang.annotation.Retention; 
import java.lang.annotation.RetentionPolicy; 

@Retention(RetentionPolicy.RUNTIME) 
public @interface Element { 

    String name(); 

} 
+6

スクリーンショットをリンクしないでコードを直接投稿してください –

+0

申し訳ありませんが、私はそれを行う方法がわかりません –

+2

@AntonGustafsson Copy + Paste? – assylias

答えて

1

クラスは確かに一つだけのアノテーションを持っています。他の2つはクラスメソッドに属します。それらに達するには、次のような何かをするでしょう:

Method getValue = Tree.class.getMethod("getValue"); //get the method 
getValue.getAnnotations(); //get annotations, only ElementField in this case 

他のすべての方法で同じです。

+0

をクリックします。それら?これを初めて使用します。 –

+1

@AntonGustafsson編集しました – kaqqao

+0

@kaqqaoありがとう、私は仕事中に手を全部持っていた – cristianhh

関連する問題