title: Name comparison in java.lang.reflect.Method.equals(Object obj)
body: <p>Here's the implementation of <code>java.lang.reflect.Method.equals(Object obj)</code> as of Java 7:</p>
  
  <pre><code>/**
   * Compares this {@code Method} against the specified object.  Returns
   * true if the objects are the same.  Two {@code Methods} are the same if
   * they were declared by the same class and have the same name
   * and formal parameter types and return type.
   */
  public boolean equals(Object obj) {
      if (obj != null &amp;&amp; obj instanceof Method) {
          Method other = (Method)obj;
          if ((getDeclaringClass() == other.getDeclaringClass())
              &amp;&amp; (getName() == other.getName())) {
              if (!returnType.equals(other.getReturnType()))
                  return false;
              /* Avoid unnecessary cloning */
              Class&lt;?&gt;[] params1 = parameterTypes;
              Class&lt;?&gt;[] params2 = other.parameterTypes;
              if (params1.length == params2.length) {
                  for (int i = 0; i &lt; params1.length; i++) {
                      if (params1[i] != params2[i])
                          return false;
                  }
                  return true;
              }
          }
      }
      return false;
  }
  </code></pre>
  
  <p>The most interesting part here is comparison of method names: <code>getName() == other.getName()</code>. Those return <code>java.lang.String</code> and hence a natural question is whether it's valid to compare them by references (<code>==</code>). While this code obviously works the question is whether it can be a source of bugs in reflection-oriented frameworks. What do you think?</p>