通过反射打印出方法和方法注解 import java.lang.annotation.Annotation;import java.lang.reflect.Method;/** * Created by Doracoin on 2017/8/18. */public class ClassUtil { private static final String TAG = "ClassUtil"; public Strin
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
/**
* Created by Doracoin on 2017/8/18.
*/
public class ClassUtil {
private static final String TAG = "ClassUtil";
public String getClassInfo(Class
cls) {
StringBuilder strBuid = new StringBuilder();
Method[] ms = cls.getDeclaredMethods();
strBuid.append(" ------------------------------------------------------------------------------------------\n");
for (Method m : ms) {
strBuid.append("| Method: " + m.getName()+"\n");
Annotation[] an = m.getDeclaredAnnotations();
strBuid.append("| └ Annotations\n");
for (Annotation a : an) {
strBuid.append("| └" + a.toString()+"\n");
}
strBuid.append("|\n");
}
strBuid.append(" ------------------------------------------------------------------------------------------\n");
return strBuid.toString();
}
}
