一个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
相关文档:
目标:实现一个汉字字符串按汉语拼音字典顺序排序。
原理:在windows环境的gbk字符集里,汉字是按汉语拼音字典顺序编码的,如“础”是B4A1,“储”是B4A2。这里有个问题就像上面的储和础这样的同音字只能遵照编码的顺序了,另外多音字也得遵照编码顺序。设计思路是先拆分汉字字符串为字符数组,获得每 ......
原文出处:http://developers.sun.com/techtopics/mobility/midp/articles/wtk23beta/
Sun Java Wireless Toolkit越来越好,2.3beta版本增加了对于三种新的API的支持:
l The Security and Trust Services APIs (SATSA, ......
一直被同步搞得晕头转向,今天遇到了要写静态方法,总担心会不会有同步问题,结果看了以下一席话,豁然开朗~~
Every method of java will have a stack, and every invokation on that
method will have it's own 'stack frame'. So the locale data of one
method invokation will not affect others.
Please do not c ......
1 Boolean VS boolean
public final class Booleanextends [url=file:///G:/html_zh_CN/html/zh_CN/api/java/lang/Object.html]Object[/url]implements [url=file:///G:/html_zh_CN/html/zh_CN/api/java/io/Serializable.html]Serializable[/url], [url=file:///G:/html_zh_CN/html/zh_CN/api/java/lang ......
一.获得控制台用户输入的信息
Java代码
/** */
/**获得控制台用户输入的信息
* @return
* @throws IOException
*/
public
  ......