1

Is this possible to get an int array in a custom annotation?

If yes, how to I call it?

Here's a dummy example to help me understand... Suppose that I have @Add() that takes an infinite number of operand.

@Add(operand1=10, operand2=20, operandx=...)

What I want is to have only one property operands.

1 Answers1

3

You can achieve what you want if you add a parameter to the interface as an array.

public @interface Add {
     int [] operands(); 
}

Then usage would be :

@Add(operands={1,2,3})

Note: var-args would not work; the compiler will reject it.

Eugene
  • 117,005
  • 15
  • 201
  • 306