Java Reflection Annotation getAnnotation(Object context, Class annotation)

Here you can find the source of getAnnotation(Object context, Class annotation)

Description

Takes the target IckleActivity and finds the given annotation (if any).

License

Apache License

Parameter

Parameter Description
injectorActivity the IckleActivity whose metadata is searched <br><br>
annotation the Class of the Annotation to look for <br><br>

Declaration

public static <T extends Annotation> T getAnnotation(Object context, Class<T> annotation) 

Method Source Code


//package com.java2s;
/*//from  w  w w. ja  v a  2s. co  m
 * #%L
 * IckleBot
 * %%
 * Copyright (C) 2013 Lonepulse
 * %%
 * 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.
 * #L%
 */

import java.lang.annotation.Annotation;

public class Main {
    /**
     * <p>Takes the target {@link IckleActivity} and finds the given 
     * annotation (if any).</p>
     * 
     * @param injectorActivity
     *          the {@link IckleActivity} whose metadata is searched 
     * <br><br>
     * @param annotation
     *          the {@link Class} of the {@link Annotation} to look for
     * <br><br>
     * @since 1.0.0
     */
    public static <T extends Annotation> T getAnnotation(Object context, Class<T> annotation) {

        Class<?> contextClass = context.getClass();

        if (contextClass.isAnnotationPresent(annotation)) {

            return contextClass.getAnnotation(annotation);
        } else {

            return null;
        }
    }
}

Related

  1. getAnnotation(Method method, Class annotationType)
  2. getAnnotation(Method method, Class annotationClass)
  3. getAnnotation(Method method, Class annotationClass)
  4. getAnnotation(Method method, Class type)
  5. getAnnotation(Object bean, final Class annotation)
  6. getAnnotation(Object instance, Class type)
  7. getAnnotation(Object obj, Class annClass)
  8. getAnnotation(Object obj, Class acl)
  9. getAnnotation(Object obj, Class annotation)