How to use constants definded in other class file as the default value in a custom annotation [duplicate]

Multi tool use
Multi tool use


How to use constants definded in other class file as the default value in a custom annotation [duplicate]



This question already has an answer here:



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 ?



This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





It works when MAX_DATA_ROW is static final
– Héctor
1 hour ago


MAX_DATA_ROW


static final





seems it doesn't recognize your value as a constant.
– Stultuske
1 hour ago




2 Answers
2



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



You must define MAX_DATA_ROW as static and final:


MAX_DATA_ROW


static


final


public class Constant {

public static final int MAX_DATA_ROW = 1;

}

1NO,EjYat8LCN2wtKs8Z54A1MmBvRg5Voj,TchJPNtk d 2ErMQne
DPe7Nf1,F5j,GYryffS2lLCJxWpTtH,0

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications