protected int compare ( MethodDesc o1 , MethodDesc o2 ) { final Class < ? > [ ] paramTypes1 = o1 . getParameterTypes ( ) ; final Class < ? > [ ] paramTypes2 = o2 . getParameterTypes ( ) ; // sort by parameter types from left to right for ( int i = 0 ; i < paramTypes1 . length ; i ++ ) { final Class < ? > class1 = paramTypes1 [ i ] ; final Class < ? > class2 = paramTypes2 [ i ] ; if ( class1 . equals ( class2 ) ) continue ; if ( class1 . isAssignableFrom ( class2 ) || Void . class . equals ( class2 ) ) return - 1 ; if ( class2 . isAssignableFrom ( class1 ) || Void . class . equals ( class1 ) ) return 1 ; } // sort by declaring class (more specific comes first). if ( ! o1 . getDeclaringClass ( ) . equals ( o2 . getDeclaringClass ( ) ) ) { if ( o1 . getDeclaringClass ( ) . isAssignableFrom ( o2 . getDeclaringClass ( ) ) ) return 1 ; if ( o2 . getDeclaringClass ( ) . isAssignableFrom ( o1 . getDeclaringClass ( ) ) ) return - 1 ; } // sort by target final int compareTo = ( ( Integer ) targets . indexOf ( o2 . target ) ) . compareTo ( targets . indexOf ( o1 . target ) ) ; return compareTo ; }
returns &gt ; 0 when o1 is more specific than o2