Here you can find the source of getAnnotationClass(Class> entityClass, Class
Parameter | Description |
---|---|
entityClass | a parameter |
annotationClass | a parameter |
public static final <T extends Annotation> T getAnnotationClass(Class<?> entityClass, Class<T> annotationClass)
//package com.java2s; /*/*from w ww.ja va2s .c o m*/ * Copyright 2015 Miguel Augusto Caligares <mcaligares@gmail.com> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.lang.annotation.Annotation; public class Main { /** * Return a specific annotation class if exist in class, otherwise return false * * @param entityClass * @param annotationClass * @return a specific annotation class if exist in class, otherwise return false * @see {@link #hasAnnotationClass(Class, Class)} */ public static final <T extends Annotation> T getAnnotationClass(Class<?> entityClass, Class<T> annotationClass) { return hasAnnotationClass(entityClass, annotationClass) ? entityClass.getAnnotation(annotationClass) : null; } /** * An convenience method, equivalent to {@link #hasAnnotationClass(Class, Class)} */ public static final <T extends Annotation> boolean hasAnnotationClass(Object object, Class<T> annotationClass) { return object != null ? hasAnnotationClass(object.getClass(), annotationClass) : null; } /** * Return true if class object has a specific annotation class, otherwise return false * * @param entityClass * @param annotationClass * @return Return true if class object has a specific annotation class, otherwise return false * @see {@link #hasAnnotation(Field, Class)} */ public static final <T extends Annotation> boolean hasAnnotationClass(Class<?> entityClass, Class<T> annotationClass) { return entityClass != null && entityClass.isAnnotationPresent(annotationClass); } }