一个Java反射机制例子
來源:http://blog.csdn.net/loyoveui/archive/2007/06/22/1662154.aspx
package test;
import java.lang.reflect.Method;
public class InvokeTest {
/**
*
* main 方法
* @param args
* void
*/
public static void main(String[] args) {
try {
InvokeTest invokeTest = new InvokeTest();
//1.第一步获取方法的映射
//String[] realArgs = {"",""};//定义一个与execute方法第1个参数对应的String数组(注意此数组只为获取方法的映射)
//Integer in = new Integer(0);//定义一个与execute方法第2个参数对应的Integer对象
//Class[] c_args = new Class[2];
//c_args[0] = realArgs.getClass();//分别获取以上两个参数的class
//c_args[1] = in.getClass();
//Method method = invokeTest.getClass().getMethod("execute", c_args);//返回值为test方法的映射(类型Method)
/**
* 注意,以上几句(11-16行)可以写成下面一句
* 目的是获取execute方法的映射,第一个参数是方法,第二个参数是execute方法所需要的参数列表,类型是class
* 所以当execute方法没有参数时,getMethod第二个参数为null即可
*/
Method method = invokeTest.getClass().getMethod("execute",
new Class[] { String[].class, Integer.class });
//2.第二步调用方法
//String[] a1={"zhong","cheng"};//这里的数组用于做真正调用时的参数
//Integer a
相关文档:
Java学习从入门到精通
一、 JDK (Java Development Kit)
JDK是整个Java的核心,包括了Java运行环境(Java Runtime Envirnment),一堆Java工具和Java基础的类库(rt.jar)。不论什么Java应用服务器实质都是内置了某个版本的JDK。因此掌握JDK是学好Java的第一步。最主流的J ......
原文出处:http://developers.sun.com/techtopics/mobility/midp/articles/wtk23beta/
Sun Java Wireless Toolkit越来越好,2.3beta版本增加了对于三种新的API的支持:
l The Security and Trust Services APIs (SATSA, ......
1、建立一个Servlet并且实现Filter接口
该类需要实现Filter接口中的init() doFilter() destory()方法
其中init()方法自动在项目启动的时候加载,doFilter()在调用xml配置的路径是加载,destory()方法在退出项目的时候进行。
public class TestFilter implements Filter{
......
/**
* 获得实效时间,当前时间推迟1个月的时间<br>
*
* @return
*/
private String getInvalidationTime() {
String invalidationTime ......