code: static Long callLongGetter(Method method, Object obj) throws InvocationTargetException  {
      try {
        return (Long) method.invoke(obj);
      } catch (IllegalAccessException e) {
        // Expected, the declaring class or interface might not be public.
      }
  
      // Iterate over all implemented/extended interfaces and attempt invoking the method with the
      // same name and parameters on each.
      for (Class<?> clazz : method.getDeclaringClass().getInterfaces()) {
        try {
          Method interfaceMethod = clazz.getMethod(method.getName(), method.getParameterTypes());
          Long result = callLongGetter(interfaceMethod, obj);
          if (result != null) {
            return result;
          }
        } catch (NoSuchMethodException e) {
          // Expected, class might implement multiple, unrelated interfaces.
        }
      }
  
      return null;
    }
docs: Attempts to call a method either directly or via one of the implemented interfaces.
  <p>
  A Method object refers to a specific method declared in a specific class. The first invocation
  might happen with method == SomeConcreteClass.publicLongGetter() and will fail if
  SomeConcreteClass is not public. We then recurse over all interfaces implemented by
  SomeConcreteClass (or extended by those interfaces and so on) until we eventually invoke
  callMethod() with method == SomePublicInterface.publicLongGetter(), which will then succeed.
  <p>
  There is a built-in assumption that the method will never return null (or, equivalently, that
  it returns the primitive data type, i.e. {@code long} rather than {@code Long}). If this
  assumption doesn't hold, the method might be called repeatedly and the returned value will be
  the one produced by the last call.