from java.lang.method
     /**
      * Returns a hashcode for this <code>Method</code>.  The hashcode is 
computed
      * as the exclusive-or of the hashcodes for the underlying
      * method's declaring class name and the method's name.
      */
     public int hashCode() {
        return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
     }

and

     /**
      * Compares this <code>Method</code> against the specified object.  Returns
      * true if the objects are the same.  Two <code>Methods</code> 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 && obj instanceof Method) {
            Method other = (Method)obj;
            if ((getDeclaringClass() == other.getDeclaringClass())
                && (getName() == other.getName())) {
                if (!returnType.equals(other.getReturnType()))
                    return false;
                /* Avoid unnecessary cloning */
                Class[] params1 = parameterTypes;
                Class[] params2 = other.parameterTypes;
                if (params1.length == params2.length) {
                    for (int i = 0; i < params1.length; i++) {
                        if (params1[i] != params2[i])
                            return false;
                    }
                    return true;
                }
            }
        }
        return false;
     }

regarding method copies and root
     // For sharing of MethodAccessors. This branching structure is
     // currently only two levels deep (i.e., one root Method and
     // potentially many Method objects pointing to it.)
     private Method              root;
....
     /**
      * Package-private routine (exposed to java.lang.Class via
      * ReflectAccess) which returns a copy of this Method. The copy's
      * "root" field points to this Method.
      */
     Method copy() {
         // This routine enables sharing of MethodAccessor objects
         // among Method objects which refer to the same underlying
         // method in the VM. (All of this contortion is only necessary
         // because of the "accessibility" bit in AccessibleObject,
         // which implicitly requires that new java.lang.reflect
         // objects be fabricated for each reflective call on Class
         // objects.)
         Method res = new Method(clazz, name, parameterTypes, returnType,
                                 exceptionTypes, modifiers, slot, signature,
                                 annotations, parameterAnnotations, 
annotationDefault);
         res.root = this;
         // Might as well eagerly propagate this if already present
         res.methodAccessor = methodAccessor;
         return res;
     }

     // Sets the MethodAccessor for this Method object and
     // (recursively) its root
     void setMethodAccessor(MethodAccessor accessor) {
         methodAccessor = accessor;
         // Propagate up
         if (root != null) {
             root.setMethodAccessor(accessor);
         }
     }

// NOTE that there is no synchronization used here. It is correct
     // (though not efficient) to generate more than one MethodAccessor
     // for a given Method. However, avoiding synchronization will
     // probably make the implementation more scalable.
     private void acquireMethodAccessor() {
         // First check to see if one has been created yet, and take it
         // if so
         MethodAccessor tmp = null;
         if (root != null) tmp = root.getMethodAccessor();
         if (tmp != null) {
             methodAccessor = tmp;
             return;
         }
         // Otherwise fabricate one and propagate it up to the root
         tmp = reflectionFactory.newMethodAccessor(this);
         setMethodAccessor(tmp);
     }

     // Returns MethodAccessor for this Method object, not looking up
     // the chain to the root
     MethodAccessor getMethodAccessor() {
         return methodAccessor;
     }


Am 06.03.2009 3:30 Uhr, schrieb Rickard Öberg:
> Michael Hunger wrote:
>> Yes I checked it. These are different method instances (unfortunately).
>>
>> But as the method count is small we can still loop through the array for 
>> small numbers instead of using HashMap.
>>
>> The method hashcode is computed cheaply just class.hashCode() ^ 
>> name.hashCode() but the equals sucks.
>
> What do you mean by method hashcode being class+name? What about
> parameter types???
>
> /Rickard
>
>
> _______________________________________________
> qi4j-dev mailing list
> [email protected]
> http://lists.ops4j.org/mailman/listinfo/qi4j-dev


_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to