假设方法的属性的返回名称是变量或访问器。
// 来自 时代Java - nowjava.com //package com.nowjava; import java.lang.reflect.Method; public class Main { /** Prefix for all isser accessor methods. */ private static final String IS_ACCESSOR_PREFIX = "is"; /** * Return name of attribute assuming method is a mutator or accessor. * * @param method the method. * @return the attribute name. */ public static String getAttributeName(final Method method) { final String methodName = method.getName(); final boolean isserAccessor = methodName .startsWith(IS_ACCESSOR_PREFIX); final String name; if (isserAccessor) { name = Character.toLowerCase(methodName.charAt(2)) + methodName.substring(3); }