AnnotationVisitor () { return new AnnotationVisitor(ASM_API_VERSION) { private @Nullable List<Object> myAcc; @Override public void visit(String name, Object value) { collectValue(value); } @Override public void visitEnum(String name, String desc, String value) { collectValue(value); } @Override public AnnotationVisitor visitArray(String name) { myAcc = new SmartList<>(); return this; } @Override public void visitEnd() { if (myAcc != null) { Object[] template = null; if (!myAcc.isEmpty()) { final Object elem = myAcc.get(0); if (elem != null) { template = ArrayUtil.newArray(elem.getClass(), 0); } } defaultValue.set(template != null? myAcc.toArray(template) : myAcc.toArray()); } } private void collectValue(Object value) { if (myAcc != null) { myAcc.add(value); } else { defaultValue.set(value); } } }; }