2

I hava below custom annotation,

@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnno {

    String value() default "";

    // use constants value defined in other file
    int capacity() default com.constant.Constant.MAX_DATA_ROW;
}

I got a compile error say:

"Attribute value must be constant"

I don't want to write a direct value to default but I want to refer it from other class. so how can I accomplish that ?

rellocs wood
  • 1,381
  • 4
  • 21
  • 36

2 Answers2

1

You must define MAX_DATA_ROW as static and final:

public class Constant {

    public static final int MAX_DATA_ROW = 1;

}
Héctor
  • 24,444
  • 35
  • 132
  • 243
1

Your constant MAX_DATA_ROW must be "public static final", otherwise it isn't a real constant.

Alexander
  • 54
  • 5