code: public static Class[] getGenericTypes(Field field) {
          try {
              ParameterizedType type = (ParameterizedType) field.getGenericType();
              Type[] types = type.getActualTypeArguments();
  
              Class<?>[] res = new Class<?>[types.length];
  
              for (int i = 0; i < types.length; i++) {
                  res[i] = (Class<?>) types[i];
              }
  
              return res;
  
          } catch (ClassCastException e) {
              return new Class<?>[] { (Class<?>) field.getGenericType() };
          }
      }
docs: Returns the list of generic types associated to the provided field (if any).
  
  @param field the field instance to process.
  @return the list of generic types associated to the provided field (if any).