code: public BshMethod getMethod(final String name, final Class<?>[] sig,
              final boolean declaredOnly) throws UtilEvalError {
          BshMethod method = null;
          // Change import precedence if we are a class body/instance
          // Get import first. Enum blocks may override class methods.
          if (this.isClass && !this.isEnum && !declaredOnly)
              method = this.getImportedMethod(name, sig);
          if (method == null && this.methods.containsKey(name)) {
              // Apply most specific signature matching
              final Class<?>[][] candidates = this.methods.get(name)
                      .stream().map(m -> m.getParameterTypes())
                      .toArray(Class<?>[][]::new);
              int idx = Reflect.findMostSpecificSignature(sig, candidates);
              if (idx != -1)
                  method = this.methods.get(name).get(idx);
          }
          if (method == null && !this.isClass && !declaredOnly)
              method = this.getImportedMethod(name, sig);
          // try parent
          if (method == null && !declaredOnly && this.parent != null)
              return this.parent.getMethod(name, sig);
          return method;
      }
docs: Get the bsh method matching the specified signature declared in this
  name space or a parent.
  <p>
  Note: this method is primarily intended for use internally. If you use
  this method outside of the bsh package you will have to be familiar with
  BeanShell's use of the Primitive wrapper class.
  @param name the name
  @param sig the sig
  @param declaredOnly if true then only methods declared directly in this
  namespace will be found and no inherited or imported methods will
  be visible.
  @return the BshMethod or null if not found
  @throws UtilEvalError the util eval error
  @see bsh.Primitive