/[classpath]/classpath/vm/reference/java/lang/reflect/Method.java
ViewVC logotype

Diff of /classpath/vm/reference/java/lang/reflect/Method.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by mark, Tue Feb 19 22:52:10 2002 UTC revision 1.7 by mark, Sat Mar 2 15:05:47 2002 UTC
# Line 145  extends AccessibleObject implements Memb Line 145  extends AccessibleObject implements Memb
145     * Compare two objects to see if they are semantically equivalent.     * Compare two objects to see if they are semantically equivalent.
146     * Two Methods are semantically equivalent if they have the same declaring     * Two Methods are semantically equivalent if they have the same declaring
147     * class, name, and parameter list.  This ignores different exception     * class, name, and parameter list.  This ignores different exception
148     * clauses, but since you can't create a Method except through the VM,     * clauses or return types.
    * this is just the == relation.  
149     *     *
150     * @param o the object to compare to     * @param o the object to compare to
151     * @return <code>true</code> if they are equal; <code>false</code> if not     * @return <code>true</code> if they are equal; <code>false</code> if not
152     */     */
153    public boolean equals(Object o)    public boolean equals(Object o)
154    {    {
155      return this == o;        // Implementation note:
156          // The following is a correct but possibly slow implementation.
157          //
158          // This class has a private field 'slot' that could be used by
159          // the VM implementation to "link" a particular method to a Class.
160          // In that case equals could be simply implemented as:
161          //
162          // if (o instanceof Method)
163          // {
164          //    Method m = (Method)o;
165          //    return m.declaringClass == this.declaringClass
166          //           && m.slot == this.slot;
167          // }
168          // return false;
169          //
170          // If a VM uses the Method class as their native/internal representation
171          // then just using the following would be optimal:
172          //
173          // return return this == o;
174          //
175    
176          if (!(o instanceof Method))
177            return false;
178    
179          Method m = (Method)o;
180          if(!name.equals(m.name))
181              return false;
182    
183          if(declaringClass != m.declaringClass)
184              return false;
185    
186          Class[] params1 = getParameterTypes();
187          Class[] params2 = m.getParameterTypes();
188          if(params1.length != params2.length)
189              return false;
190    
191          for(int i = 0; i < params1.length; i++)
192              if(params1[i] != params2[i])
193                  return false;
194    
195          return true;
196    }    }
197    
198    /**    /**

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26