2009-12-07 60 views
3

爲什麼此代碼打印0?無法找到班級註釋

@Table(name = "source") 
public class SourceDetails implements DatabaseEntity{ 

    public static void main(String[] args) { 
     System.out.println(SourceDetails.class.getAnnotations().length); 
    } 
... 
} 
+0

它是javax.persistence.Table?或者你的@Table? – Bozho 2009-12-07 09:59:21

回答

4

因爲您沒有將註釋的保留設置爲運行時。

@Retention(RetentionPolicy.RUNTIME) 
@interface Table{ 
    String name(); 

    int intValue(); 
} 
+1

如果它是javax.persistence.Table註釋,則它設置爲運行時。 – Bozho 2009-12-07 09:58:37

+0

不,我們自己的註釋。 – ripper234 2009-12-07 10:05:00