0

I have a custom annotation which is declared as below and have some implementation for this.

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface SampleTestCase {
    public int caseID() default -1;
    public int suiteId() default -1;
}

Now, I am trying to use this annotation and trying to send runtime parameters to it.

ConfigHelper config = new ConfigHelper();
int caseId = config.getTestCaseID();

@SampleTestCase(caseID=caseId,suiteId="Test")
public void testCaseOne(){
    Assert.assertTrue(true);
}

Getting an error as "The value for annotation attribute TivoTestCase.caseID must be a constant expression".

Is there any way to pass dynamic parameters to an annotation other than this way??

azro
  • 53,056
  • 7
  • 34
  • 70
  • 1
    no. An annotation requires a constant. It would be difficult to bind a not-yet-decided value on compile-time – Stultuske Jan 28 '19 at 13:51
  • See https://stackoverflow.com/questions/14268981/modify-a-class-definitions-annotation-string-parameter-at-runtime – Ori Marko Jan 28 '19 at 13:56

0 Answers0