提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
获取Is和获取方法值
/* from nowjava - 时 代 Java*/ //package com.nowjava; import java.lang.reflect.Method; public class Main { public static void main(String[] argv) throws Exception { Class c = String.class; System.out.println(getIsAndGetMethodValue(c)); } public static String getIsAndGetMethodValue(Class c) { //NowJava.com - 时代Java StringBuffer sb = new StringBuffer(); Method[] methods = c.getMethods(); sb.append("[\n"); try { Object object = c.newInstance(); for (int i = 0; i < methods.length; i++) { if (methods[i].getName().startsWith("is") || methods[i].getName().startsWith("get") || methods[i].getName().startsWith("do")) { sb.append("\t" + methods[i].getName() + " : " + methods[i].invoke(object) +