1

Lets say I have got such code:

private static final int[] ARRAY = {5, 10, 15};

/**
 * ????
 */
public void doSomething()
{}

I am wondering, if is there any way to put value of the ARRAY into documentation of doSomething() method. I can see that @value #ARRAY isn't working at all for arrays :( @link #ARRAY is not showing me the value.

Am I missing something?

5
  • Why won't you use Enum instead of array? Commented Dec 26, 2013 at 21:43
  • Because when i try to make enum where values are numbers, it gives me "Unexpected token" error Commented Dec 26, 2013 at 21:54
  • This happens because Java identifier (name of variable, method or class) cannot start with a digit. You can however store a numeric value, as a property of each enum's instance. See enum Planet example: docs.oracle.com/javase/tutorial/java/javaOO/enum.html Commented Dec 26, 2013 at 22:02
  • Well yes, but in my case nothing(like a planet) hides behind the number. Lets say i would like to store in ARRAY PI numbers up to 10, it would be nice to see their values in JavaDocs. You see storing them as enum and creating new name for each one doesn't make any sense. Commented Dec 26, 2013 at 22:20
  • Could you please tell us what's your actuall array and method? Maybe there's another approach to solve this problem? Commented Dec 26, 2013 at 22:50

1 Answer 1

2

The problem is that @value only works for constants, i.e. static final values. The array contents are not constants, only the array object itself is. You can change the values at any time. So it doesn't make sense, technically, to show the values. The array object itself can't be shown at Javadoc creation time in any useful way, like any other object (except Strings).

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

2 Comments

So there is no way to do what i would like to? Array with always constant values that could be seen in Docs
You could define constants and use them as array values. But an array can't be made immutable.

Your Answer

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