private static boolean isMethodBetter(
            JavaAbstractMethod method1,
            int precision1,
            JavaAbstractMethod method2,
            int precision2)
    {
        //Methods comparison is done in a simplified way compared to the way how Java compiler
        //chooses the best method. The main difference is in the comparison of methods with variable
        //numbers of arguments, but such methods are not used very often, so the solution seems
        //to be suitable.
        
        //If one method has a variable number of arguments, and the other one does not, the
        //method with the fixed number of arguments is preferred.
        boolean varArgs1 = method1.isVarArgs();
        boolean varArgs2 = method2.isVarArgs();
        if (varArgs1 != varArgs2) {
            return varArgs2;
        }
        
        //Otherwise - check parameter types.
        Class<?>[] params1 = method1.getParameterTypes();
        Class<?>[] params2 = method2.getParameterTypes();
        int len = Math.min(params1.length, params2.length);
        
        for (int i = 0; i < len; ++i) {
            Class<?> type1 = params1[i];
            Class<?> type2 = params2[i];
            
            if (!type1.equals(type2)) {
                if (precision1 > precision2) {
                    return true;
                }
                
                return isTypeBetter(type1, type2);
            }
            
        }
        
        return false;
    }