I wrote the following code to read constants from annotations:
public class ContentUtils {
static {
String[] videoFormats = null;
String[] imageFormats = null;
try {
Field multipartFileField = MultipartFileWrapper.class.getField("multipartFile");
Extensions annotation = multipartFileField.getAnnotation(Extensions.class);
imageFormats = annotation.imageFormats();
videoFormats = annotation.videoFormats();
} catch (NoSuchFieldException e) {
if (imageFormats == null) {
imageFormats = new String[]{};
}
if (videoFormats == null) {
videoFormats = new String[]{};
}
}
ACCEPTED_IMAGE_FORMATS = imageFormats;
ACCEPTED_VIDEO_FORMATS = videoFormats;
}
public static final String[] ACCEPTED_IMAGE_FORMATS;
public static final String[] ACCEPTED_VIDEO_FORMATS;
}
Is there a way to rewrite it better?
Or something else improve at this code?
NoSuchFieldException
? \$\endgroup\$