java反射获得方法的返回值类型,,package cn.opackage cn.outofmemory.snippets.core;public class GetReturnType { public static void main(String args[]){ Class> clazz = java.lang.ThreadLocal.class; Method[] methods; // return class and super class methods methods = clazz.getDeclaredMethods(); for (int i = 0; i < methods.length; i++){ System.out.println(methods[i] + ", return type :" + methods[i].getReturnType()); } }}

输出:public java.lang.Object java.lang.ThreadLocal.get(), return type :class java.lang.Objectpublic void java.lang.ThreadLocal.remove(), return type :voidstatic java.lang.ThreadLocal$ThreadLocalMap java.lang.ThreadLocal.createInheritedMap(java.lang.ThreadLocal$ThreadLocalMap), return type :class java.lang.ThreadLocal$ThreadLocalMapstatic int java.lang.ThreadLocal.access$400(java.lang.ThreadLocal), return type :intpublic void java.lang.ThreadLocal.set(java.lang.Object), return type :voidprivate java.lang.Object java.lang.ThreadLocal.setInitialValue(), return type :class java.lang.Objectjava.lang.Object java.lang.ThreadLocal.childValue(java.lang.Object), return type :class java.lang.Objectvoid java.lang.ThreadLocal.createMap(java.lang.Thread,java.lang.Object), return type :voidjava.lang.ThreadLocal$ThreadLocalMap java.lang.ThreadLocal.getMap(java.lang.Thread), return type :class java.lang.ThreadLocal$ThreadLocalMapprotected java.lang.Object java.lang.ThreadLocal.initialValue(), return type :class java.lang.Objectprivate static int java.lang.ThreadLocal.nextHashCode(), return type :int