Here you can find the source of getAnnotation(Class
Parameter | Description |
---|---|
annotations | a parameter |
@SuppressWarnings("unchecked") public static final <T extends Annotation> T getAnnotation(Class<T> lookingFor, Annotation[] annotations)
//package com.java2s; /***************************************************************************** * Copyright 2011 Zdenko Vrabel/*from w ww . j a v a2 s . c o m*/ * * 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 { /** * Method searchs annotation in annotations array and return * it. If annotation is not occured, then method return null. * * @param annotations * @return * * @return */ @SuppressWarnings("unchecked") public static final <T extends Annotation> T getAnnotation(Class<T> lookingFor, Annotation[] annotations) { if (annotations != null) { for (int i = 0; i < annotations.length; ++i) { if (lookingFor.isInstance(annotations[i])) { return (T) annotations[i]; } } } return null; } }