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;
}
}
相关文档:
create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',
@pagesize int output,--每页显示记录条数
@currentpage int output,--第几页
@orderid nvarchar(50),--主键排序
@sort int,--排序方式,1表示升序,0表示降序排列
......
给数组赋值的便捷方式: String s=reader.nextLine(); char a[]=s.toCharArray();这样就不用使用麻烦的for循环来赋值了
输出数组内容的便捷方式:String code=new String(a); //a是一个数组名
System.out.println("原文是"+code);
&nb ......
一、从根本上认识java.lang.String类和String池
首先,我建议先看看String类的源码实现,这是从本质上认识String类的根本出发点。从中可以看到:
1、String类是final的,不可被继承。public final class String。
2、String类是的本质是字符数组char[], 并且其值不可改变。private final char value[];
然后打开Str ......
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 ......