如何通过反射打印出方法及其方法注解的长尾词?

2026-04-10 13:571阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计197个文字,预计阅读时间需要1分钟。

如何通过反射打印出方法及其方法注解的长尾词?

通过反射打印类方法和注解的方法和注意事项:

如何通过反射打印出方法及其方法注解的长尾词?

javaimport 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 static void printMethodsAndAnnotations(Class clazz) { Method[] methods=clazz.getDeclaredMethods(); for (Method method : methods) { System.out.println(Method: + method.getName()); Annotation[] annotations=method.getDeclaredAnnotations(); if (annotations.length > 0) { System.out.println(Annotations:); for (Annotation annotation : annotations) { System.out.println( - + annotation.toString()); } } System.out.println(Method details: + method.toString()); } }}

通过反射打印出方法和方法注解

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(); } }

本文共计197个文字,预计阅读时间需要1分钟。

如何通过反射打印出方法及其方法注解的长尾词?

通过反射打印类方法和注解的方法和注意事项:

如何通过反射打印出方法及其方法注解的长尾词?

javaimport 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 static void printMethodsAndAnnotations(Class clazz) { Method[] methods=clazz.getDeclaredMethods(); for (Method method : methods) { System.out.println(Method: + method.getName()); Annotation[] annotations=method.getDeclaredAnnotations(); if (annotations.length > 0) { System.out.println(Annotations:); for (Annotation annotation : annotations) { System.out.println( - + annotation.toString()); } } System.out.println(Method details: + method.toString()); } }}

通过反射打印出方法和方法注解

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(); } }