views:

53

answers:

1

Why does this code print 0?

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

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

Because you didn't set the retention of the annotation to runtime.

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

  int intValue();
}
Jerome
if it is the javax.persistence.Table annotation, it is set to Runtime.
Bozho
No, our own annotation.
ripper234