Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mark separate dimensions of an Array with Annotations

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?

like image 697
Vitaly Avatar asked Oct 29 '15 21:10

Vitaly


1 Answers

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.

like image 154
kapex Avatar answered Nov 12 '22 08:11

kapex