![]() ![]() Perhaps it doesn't like the fact that arrays are mutable? Hmm. However, my actual motivation is to use that restriction in an. Restrictions r1 (64) The reason being is, I am using enum to restrict the type of restriction that could be used, and be able to assign a value to that restriction. Offhand, I don't recall ever having tried this with an array, so you may be running into some issues with slight differences in how arrays are represented as annotation parameters compared to Java variables? But as for the other part of your question, you could definitely use a constant String without any problems.ĮDIT: I've just tried this with a String array, and didn't run into the problem you mentioned - however the compiler did tell me that the "attribute value must be constant" despite the array being defined as public static final String. So that I could happily do something like this, which is perfectly legal syntax. Note that it's possible to pass the TEST_TIMEOUT constant straight into the annotation. Private static final int TEST_TIMEOUT = 60000 // one minute per void testJDK()ĪssertTrue("Something is very wrong", Boolean.TRUE) It is possible to use some compile time tools (ant, maven) to config it if the value is known before you try to run the program. case you made the field as final the most fundamental reason you are not able to inject value into the field using the value is that Java replaces static final 'variable' occurrences in the code with the actual values. the default value of an element must be a non-null constant expression. The value for the annotation attribute Scheduled.cron attribute must be a constant expression. ![]() See also here: How to supply value to an annotation from a Constant java. In an annotation, an optional element is specified with the default modifier. As a quick example, I use something like this fairly often: import The value for an annotation must be a compile time constant, so there is no simple way of doing what you are trying to do. a static, final variable) as the parameter for an annotation. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |