In Java 8 we can mark separate dimensions of array with annotations (see section 10.2 in JLS 8). For example,
int @a[] a;
int @a[] @b[] a;
void someMethod(int @a[] @b... y) {}
Then we can parse such declarations with Java Reflection to implement some specific logic.
Do you know any practical applications of this feature in real Java frameworks or Java libraries?
An example where this kind of annotation placement could be useful is the Checker Framework.
It could get used to create mutable/immutable or (non-)nullable rows - basically whatever you might want to annotate a whole array with, but only for a single row.
Object @NonNull [] @Nullable [] a;
Other than that, it could get used for documentation, like annotations explaining the purpose of each dimension.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With