------- <a href="http://www.itheima.com" target="blank">android培训</a>
代码演示:
<pre name="code" class="java">public class ProxyTest {
public static void main(String[] args) {
//获取类Proxy 字节码
Class clszz = Proxy.getProxyClass(Collection.class.getClassLoader(), Collection.class);
System.out.println(clszz.getName());
Constructor[] constructors = clszz.getConstructors();
//打印构造函数
for(Constructor constructor : constructors){
String name = constructor.getName();
StringBuilder sb = new StringBuilder(name);
sb.append('(');
Class[] classParams = constructor.getParameterTypes();
for(Class classParam : classParams){
sb.append(classParam.getName()).append(',');
}
if(classParams.length != 0){
sb.deleteCharAt(sb.length() - 1);
}
sb.append(')');
System.out.println(sb);
}
//获取类类的方法
Method[] methods = clszz.getMethods();
for(Method method : methods){
String name = method.getName();
StringBuilder sb = new StringBuilder(name);
sb.append('(');
Class[] classParams = method.getParameterTypes();
for(Class classParam : classParams){
sb.append(classParam.getName()).append(',');
}
if(classParams.length != 0){
sb.deleteCharAt(sb.length() - 1);
}
sb.append(')');
System.out.println(sb);
}
}
}
<a href="http://www.itheima.com" target="blank">java培训</a>、期待与您交流! ----------