Here you can find the source of getAnnotation(Class> type, Class extends Annotation> annotationType)
Parameter | Description |
---|---|
type | the type which might be annotated |
annotationType | the annotation type |
public static Annotation getAnnotation(Class<?> type, Class<? extends Annotation> annotationType)
//package com.java2s; /*//from w w w .ja va 2 s. com * DuDe - The Duplicate Detection Toolkit * * Copyright (C) 2010 Hasso-Plattner-Institut f?r Softwaresystemtechnik GmbH, * Potsdam, Germany * * This file is part of DuDe. * * DuDe is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * DuDe is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with DuDe. If not, see <http://www.gnu.org/licenses/>. * */ import java.lang.annotation.Annotation; public class Main { /** * Returns the first annotation of the specified annotation type for the given type.<br> * If no annotation is found for the type, the hierarchical ancestors are examined. * * @param type * the type which might be annotated * @param annotationType * the annotation type * @return the annotation or null */ public static Annotation getAnnotation(Class<?> type, Class<? extends Annotation> annotationType) { Annotation annotation = null; for (Class<?> t = type; annotation == null && t != null; t = t.getSuperclass()) annotation = t.getAnnotation(annotationType); return annotation; } }