java.lang.reflect.Method.toString()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(134)

本文整理了Java中java.lang.reflect.Method.toString()方法的一些代码示例,展示了Method.toString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Method.toString()方法的具体详情如下:
包路径:java.lang.reflect.Method
类名称:Method
方法名:toString

Method.toString介绍

[英]Returns a string describing this Method. The string is formatted as the method access modifiers, if any, followed by the method return type, followed by a space, followed by the class declaring the method, followed by a period, followed by the method name, followed by a parenthesized, comma-separated list of the method's formal parameter types. If the method throws checked exceptions, the parameter list is followed by a space, followed by the word throws followed by a comma-separated list of the thrown exception types. For example:

public boolean java.lang.Object.equals(java.lang.Object)

The access modifiers are placed in canonical order as specified by "The Java Language Specification". This is public, protected or private first, and then other modifiers in the following order: abstract, static, final, synchronized, native, strictfp.
[中]返回描述此方法的字符串。字符串的格式为方法访问修饰符(如果有),后跟方法返回类型,后跟空格,后跟声明方法的类,后跟句点,后跟方法名称,后跟方法的形式参数类型的括号逗号分隔列表。如果该方法抛出选中的异常,则参数列表后面会有一个空格,后面是单词throws,后面是逗号分隔的抛出异常类型列表。例如:

public boolean java.lang.Object.equals(java.lang.Object)

访问修饰符按“Java语言规范”指定的规范顺序放置。首先是public、protected或private,然后是按以下顺序排列的其他修饰符:abstract、static、final、synchronized、native、strictfp。

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Override
public String toString() {
  return this.method.toString();
}

代码示例来源:origin: junit-team/junit4

@Override
  public String toString() {
    return method.toString();
  }
}

代码示例来源:origin: google/j2objc

@Override
  protected String getReplacementFor(String placeholder) {
    return method.toString();
  }
}

代码示例来源:origin: robolectric/robolectric

@Override
 public String describe() {
  return shadowMethod.toString();
 }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
  public int compareTo(MethodCacheKey other) {
    int result = this.method.getName().compareTo(other.method.getName());
    if (result == 0) {
      result = this.method.toString().compareTo(other.method.toString());
    }
    return result;
  }
}

代码示例来源:origin: com.h2database/h2

@Override
public String toString() {
  return method.toString();
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public int compareTo(MethodClassKey other) {
  int result = this.method.getName().compareTo(other.method.getName());
  if (result == 0) {
    result = this.method.toString().compareTo(other.method.toString());
    if (result == 0 && this.targetClass != null && other.targetClass != null) {
      result = this.targetClass.getName().compareTo(other.targetClass.getName());
    }
  }
  return result;
}

代码示例来源:origin: com.h2database/h2

@Override
  public int compare(Method o1, Method o2) {
    return o1.toString().compareTo(o2.toString());
  }
});

代码示例来源:origin: jenkinsci/jenkins

PropertyType(Method getter) {
  this(getter.getReturnType(),getter.getGenericReturnType(),getter.toString());
}

代码示例来源:origin: knightliao/disconf

/**
 *
 */
public static void printFileItemMethod(Set<Method> disconfFileItemSet) {
  for (Method item : disconfFileItemSet) {
    LOGGER.info(item.toString());
  }
}

代码示例来源:origin: junit-team/junit4

public int compare(Method m1, Method m2) {
    final int comparison = m1.getName().compareTo(m2.getName());
    if (comparison != 0) {
      return comparison;
    }
    return m1.toString().compareTo(m2.toString());
  }
};

代码示例来源:origin: google/j2objc

public int compare(Method m1, Method m2) {
    final int comparison = m1.getName().compareTo(m2.getName());
    if (comparison != 0) {
      return comparison;
    }
    return m1.toString().compareTo(m2.toString());
  }
};

代码示例来源:origin: spring-projects/spring-framework

private List<Method> findCandidateWriteMethods(MethodDescriptor[] methodDescriptors) {
  List<Method> matches = new ArrayList<>();
  for (MethodDescriptor methodDescriptor : methodDescriptors) {
    Method method = methodDescriptor.getMethod();
    if (isCandidateWriteMethod(method)) {
      matches.add(method);
    }
  }
  // Sort non-void returning write methods to guard against the ill effects of
  // non-deterministic sorting of methods returned from Class#getDeclaredMethods
  // under JDK 7. See http://bugs.sun.com/view_bug.do?bug_id=7023180
  matches.sort((m1, m2) -> m2.toString().compareTo(m1.toString()));
  return matches;
}

代码示例来源:origin: org.springframework/spring-core

@Override
public int compareTo(MethodClassKey other) {
  int result = this.method.getName().compareTo(other.method.getName());
  if (result == 0) {
    result = this.method.toString().compareTo(other.method.toString());
    if (result == 0 && this.targetClass != null && other.targetClass != null) {
      result = this.targetClass.getName().compareTo(other.targetClass.getName());
    }
  }
  return result;
}

代码示例来源:origin: org.testng/testng

@Override
 public String toString() {
  if (m_method != null) return m_method.toString();
  else return m_constructor.toString();
 }
}

代码示例来源:origin: robolectric/robolectric

@Override public String toString() {
  return method.toString();
 }
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Obtains the display name of the given initialization task
 */
protected String getDisplayNameOf(Method e, T i) {
  Class<?> c = e.getDeclaringClass();
  String key = displayNameOf(i);
  if (key.length()==0)  return c.getSimpleName()+"."+e.getName();
  try {
    ResourceBundleHolder rb = ResourceBundleHolder.get(
        c.getClassLoader().loadClass(c.getPackage().getName() + ".Messages"));
    return rb.format(key);
  } catch (ClassNotFoundException x) {
    LOGGER.log(WARNING, "Failed to load "+x.getMessage()+" for "+e.toString(),x);
    return key;
  } catch (MissingResourceException x) {
    LOGGER.log(WARNING, "Could not find key '" + key + "' in " + c.getPackage().getName() + ".Messages", x);
    return key;
  }
}

代码示例来源:origin: spring-projects/spring-framework

Method method = testContext.getTestMethod();
String elementType = (classLevel ? "class" : "method");
String elementName = (classLevel ? clazz.getName() : method.toString());

代码示例来源:origin: weibocom/motan

private static <T> RestfulClientInvoker createClientInvoker(Class<T> clazz, Method method, ResteasyWebTarget base,
    ProxyConfig config) {
  Set<String> httpMethods = IsHttpMethod.getHttpMethods(method);
  if (httpMethods == null || httpMethods.size() != 1) {
    throw new RuntimeException(
        "You must use at least one, but no more than one http method annotation on: " + method.toString());
  }
  RestfulClientInvoker invoker = new RestfulClientInvoker(base, clazz, method, config);
  invoker.setHttpMethod(httpMethods.iterator().next());
  return invoker;
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void noCacheResolved() {
  Method method = ReflectionUtils.findMethod(SimpleService.class, "noCacheResolved", Object.class);
  try {
    this.simpleService.noCacheResolved(new Object());
    fail("Should have failed, no cache resolved");
  }
  catch (IllegalStateException ex) {
    assertTrue("Reference to the method must be contained in the message", ex.getMessage().contains(method.toString()));
  }
}

相关文章

微信公众号

最新文章

更多