Field (@NotNull Class<?> clazz, @NotNull String fieldName, @Nullable Class<?> fieldType) { for (Field field : clazz.getDeclaredFields()) { if (fieldName.equals(field.getName()) && (fieldType == null || fieldType.isAssignableFrom(field.getType()))) { field.setAccessible(true); return field; } } Class<?> superClass = clazz.getSuperclass(); if (superClass != null) { Field result = findField(superClass, fieldName, fieldType); if (result != null) return result; } for (Class<?> each : clazz.getInterfaces()) { Field result = findField(each, fieldName, fieldType); if (result != null) return result; } return null; }