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

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.