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 |
/** |
/** |