Here you can find the source of findFieldsAnnotatedWith(final Class> type, final Class extends Annotation> annotation)
public static List<Field> findFieldsAnnotatedWith(final Class<?> type, final Class<? extends Annotation> annotation)
//package com.java2s; /*// w w w.j a v a 2 s .c om * @(#)ReflectUtils.java 2014?1?1? ????23:33:33 * * Copyright (c) 2011-2014 Makersoft.org all rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * */ import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Main { public static List<Field> findFieldsAnnotatedWith(final Class<?> type, final Class<? extends Annotation> annotation) { List<Field> fields = new ArrayList<Field>(); Class<?> klass = type; while (klass != null && klass != Object.class) { // need to iterated thought hierarchy in order to retrieve // methods from above the current instance // iterate though the list of methods declared in the class represented by klass // variable, and add those annotated with the specified annotation final List<Field> allFields = new ArrayList<Field>(Arrays.asList(klass.getDeclaredFields())); for (final Field field : allFields) { if (annotation == null || field.isAnnotationPresent(annotation)) { // Annotation annotInstance = method.getAnnotation(annotation); // TODO process annotInstance fields.add(field); } } // move to the upper class in the hierarchy in search for more fields klass = klass.getSuperclass(); } return fields; } }