JAVA反射机制事例二
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
try {
Class cls = com.lwf.util.CommonUtil.class;
Object obj = cls.newInstance();
Method addMethod = cls.getMethod("add", new Class[]{int.class,int.class});
Object value = addMethod.invoke(obj, new Object[]{new Integer(12),new Integer(23)});
System.out.println((Integer)value);
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
package com.lwf.util;
public class CommonUtil {
public static void getName(){
System.out.println("this is a getName function");
}
public void getMethod(){
System.out.println("this is a getMethod funciton");
}
public int add(int m ,int n){
return m + n;
}
}
相关文档:
package demo;
class TA{
//这个程序要好好理解,常量不是属于类的,它在内存中有一块单独的存储区域,何类TA无任何关系
// public static final int m=9;
// 静态变量是属于类的,它的存储区域与类相关
public static int m=9;
static {
System.out.println("In Static m=" ......
/**
* 处理时间异常 Date to String
* 如果转换出现异常会给默认值00:00
* @param time
* @param sdf
* @return
*/
public static String handleDateParseException(Object time){
String tempTime = "00:00";
try{
......
报文鉴别在身份认证中占重要位置,是认证系统的一个重要环节,在金融和商业系统中广泛应用。
报文鉴别常用报文鉴别码(Message Authentication Code,即MAC)作为鉴别的基础,
......
package org.mingyuan.fetcher;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
i ......