title: What is the new way of getting all methods of a class, including inherited default methods of Java 8?
body: <p>I want to get all methods of a class, including public, protected, package and private methods, and including inherited methods. </p>
  
  <p>Remember: </p>
  
  <ul>
  <li><code>Class.getDeclaredMethods()</code> gets public, protected, package and private
  methods, <strong>but</strong> excludes inherited methods. </li>
  <li><code>Class.getMethods</code> gets inherited methods, <strong>but</strong> only the public ones.</li>
  </ul>
  
  <p>Before Java 8 we could do something along the lines of:</p>
  
  <pre><code>Collection&lt;Method&gt; found = new ArrayList&lt;Method&gt;();
  while (clazz != null) {
      for (Method m1 : clazz.getDeclaredMethods()) {
          boolean overridden = false;
  
          for (Method m2 : found) {
              if (m2.getName().equals(m1.getName())
                &amp;&amp; Arrays.deepEquals(m1.getParameterTypes(), m2
                    .getParameterTypes())) {
              overridden = true;
              break;
              }
          }
          if (!overridden) found.add(m1);
      }
  
      clazz = clazz.getSuperclass();
  }
  return found;
  </code></pre>
  
  <p>But now, if the class implements some interface with <strong>default methods</strong> which are not overridden by concrete superclasses, these methods will escape the above detection. Besides, there are now rules concerning default methods with the same name, and these rules must be taken into account as well.</p>
  
  <p><strong>Question:</strong> What is the current recommended way of getting <strong>all</strong> methods of a class:</p>
  
  <p>The most common definition of "all" should be the methods that can be directly accessed inside an instance method of the class, without the use of <code>super</code> or class names:</p>
  
  <ul>
  <li>Include public, protected, package and private methods declared in the class itself.</li>
  <li>Include protected methods of its superclasses.</li>
  <li>Include package methods of its superclasses of the same package.</li>
  <li>Include default methods of its interfaces (those not overridden/hidden, see <a href="http://www.lambdafaq.org/how-are-conflicting-method-declarations-resolved/" rel="noreferrer">here</a> and <a href="http://www.lambdafaq.org/what-about-the-diamond-problem/" rel="noreferrer">here</a>).</li>
  <li>Include static methods (class and superclasses) with the appropriate accessibility.</li>
  <li>Don't include private methods of superclasses.</li>
  <li>Don't include overridden methods.</li>
  <li>Don't include hidden methods (in special, don't include hidden static methods).</li>
  <li>Don't include synthetic/bridge methods.</li>
  <li>Don't include methods not allowed by Java, even if the JVM allows them.</li>
  </ul>
  
  <p>So, the above definition fits the following signature when both boolean flags are <code>false</code>:</p>
  
  <pre><code>public Collection&lt;Method&gt; getAllMethods(Class clazz,
                                 boolean includeAllPackageAndPrivateMethodsOfSuperclasses,
                                 boolean includeOverridenAndHidden)
  </code></pre>
  
  <p>The ideal, canonical answer, should allow for these boolean flags.</p>