Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Multi-dimensional arrays
import java.lang.annotation.*;
import java.lang.reflect.*;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE_USE)
@interface TA {
int value();
}
public class MyClass {
public void test(@TA(0) String @TA(1) [] @TA(2) [] f @TA(3) [] @TA(4) [],
@TA(0) String @TA(3) [] @TA(4) [] @TA(1) [] @TA(2) [] g) { }
public static void main(String[] args) throws NoSuchMethodException {
Method test = MyClass.class.getMethod("test", String[][][][].class,
String[][][][].class);
System.out.println(readVals(test.getAnnotatedParameterTypes()[0]));
System.out.println(readVals(test.getAnnotatedParameterTypes()[1]));
}
private static String readVals(AnnotatedType type) {
String val = "(" + type.getAnnotation(TA.class).value() + ")";
return type instanceof AnnotatedArrayType ?
val + readVals(((AnnotatedArrayType) type).getAnnotatedGenericComponentType()) :
val;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment