[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Method.equals()
From: |
Mark Wielaard |
Subject: |
Re: Method.equals() |
Date: |
02 Mar 2002 16:04:45 +0100 |
Hi,
On Wed, 2002-02-20 at 03:19, Bryce McKinlay wrote:
> Cierniak, Michal wrote:
> >
> >But I thought that Bryce indicated in his message that he also liked the
> >patch submitted by Gansha. It sounds like this modification is useful for
> >both ORP and GCJ since they both have their own internal data structures to
> >represent a method.
>
> Right. Gansha's implementation should be the one that goes in
> vm/reference. It may not be optimal for all VMs, but it is always
> correct and most accurately matches the JDK spec, and it is the
> implementation required for both ORP and GCJ.
OK. I think I understand the issue now. So this is the patch that
went in:
--- vm/reference/java/lang/reflect/Method.java 19 Feb 2002 22:52:10
-0000
1.6
+++ vm/reference/java/lang/reflect/Method.java 2 Mar 2002 15:03:20 -0000
@@ -153,7 +153,46 @@
*/
public boolean equals(Object o)
{
- return this == o;
+ // Implementation note:
+ // The following is a correct but possibly slow implementation.
+ //
+ // This class has a private field 'slot' that could be used by
+ // the VM implementation to "link" a particular method to a
Class.
+ // In that case equals could be simply implemented as:
+ //
+ // if (o instanceof Method)
+ // {
+ // Method m = (Method)o;
+ // return m.declaringClass == this.declaringClass
+ // && m.slot == this.slot;
+ // }
+ // return false;
+ //
+ // If a VM uses the Method class as their native/internal
representation
+ // then just using the following would be optimal:
+ //
+ // return return this == o;
+ //
+
+ if (!(o instanceof Method))
+ return false;
+
+ Method m = (Method)o;
+ if(!name.equals(m.getName()))
+ return false;
+
+ if(declaringClass != m.declaringClass)
+ return false;
+
+ Class[] params1 = getParameterTypes();
+ Class[] params2 = m.getParameterTypes();
+ if(params1.length != params2.length)
+ return false;
+ for(int i = 0; i < params1.length; i++)
+ if(params1[i] != params2[i])
+ return false;
+
+ return true;
}
/**
There is now also a corresponding Mauve test case. Although I have been
unable to test it because for some reason my Orp doesn't like the CVS
Classpath anymore :(
Cheers,
Mark
- Re: Method.equals(),
Mark Wielaard <=