是元素的必填字段
//package com.nowjava;/* 来自 时 代 J a v a 公 众 号*/ import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; public class Main { private static final String NON_NULL_ANNOTATION_NAME = "NonNull"; private static final String NOT_NULL_ANNOTATION_NAME = "NotNull"; public static boolean isFieldRequired(Element element) { return hasAnnotationWithName(element, NOT_NULL_ANNOTATION_NAME) || hasAnnotationWithName(element, NON_NULL_ANNOTATION_NAME); } public static boolean hasAnnotationWithName(Element element, String simpleName) { for (AnnotationMirror mirror : element.getAnnotationMirrors()) { String annotationName = mirror.getAnnotationType().asElement() .getSimpleName().toString()