javaÖеÄreflect»úÖÆ£¨×ª£©
Java
Reflection (JAVA·´Éä)
Reflection ÊÇ Java
³ÌÐò¿ª·¢ÓïÑÔµÄÌØÕ÷Ö®Ò»£¬ËüÔÊÐíÔËÐÐÖÐµÄ Java
³ÌÐò¶Ô×ÔÉí½øÐмì²é£¬»òÕß˵“×ÔÉ󔣬²¢ÄÜÖ±½Ó²Ù×÷³ÌÐòµÄÄÚ²¿ÊôÐÔ¡£ÀýÈ磬ʹÓÃËüÄÜ»ñµÃ Java
ÀàÖи÷³ÉÔ±µÄÃû³Æ²¢ÏÔʾ³öÀ´¡£
Java
µÄÕâÒ»ÄÜÁ¦ÔÚʵ¼ÊÓ¦ÓÃÖÐÒ²ÐíÓõò»ÊǺܶ࣬µ«ÊÇÔÚÆäËüµÄ³ÌÐòÉè¼ÆÓïÑÔÖиù±¾¾Í²»´æÔÚÕâÒ»ÌØÐÔ¡£ÀýÈ磬Pascal¡¢C »òÕß C++ ÖоÍûÓа취ÔÚ³ÌÐòÖлñµÃº¯Êý¶¨ÒåÏà¹ØµÄÐÅÏ¢¡£
JavaBean ÊÇ reflection µÄʵ¼ÊÓ¦ÓÃÖ®Ò»£¬ËüÄÜÈÃһЩ¹¤¾ß¿ÉÊÓ»¯µÄ²Ù×÷Èí¼þ×é¼þ¡£ÕâЩ¹¤¾ßͨ¹ý reflection ¶¯Ì¬µÄÔØÈ벢ȡµÃ Java
×é¼þ(Àà) µÄÊôÐÔ¡£
1. Ò»¸ö¼òµ¥µÄÀý×Ó
¿¼ÂÇÏÂÃæÕâ¸ö¼òµ¥µÄÀý×Ó£¬ÈÃÎÒÃÇ¿´¿´ reflection ÊÇÈçºÎ¹¤×÷µÄ¡£
import java
.lang.reflect.*;
public class DumpMethods {
public static void main(String args[]) {
try {
Class c = Class.forName(args[0]);
Method m[] = c.getDeclaredMethods();
for (int i = 0; i < m.length; i++)
System.out.println(m[i].toString());
} catch (Throwable e) {
System.err.println(e);
}
}
}
°´ÈçÏÂÓï¾äÖ´ÐУº
java
DumpMethods java
.util.Stack
ËüµÄ½á¹ûÊä³öΪ£º
public java
.lang.Object java
.util.Stack.push(java
.lang.Object)
public synchronized java
.lang.Object java
.util.Stack.pop()
public synchronized java
.lang.Object java
.util.Stack.peek()
public boolean java
.util.Stack.empty()
public synchronized int java
.util.Stack.search(java
.lang.Object)
ÕâÑù¾ÍÁгöÁËjava.util.Stack ÀàµÄ¸÷·½·¨ÃûÒÔ¼°ËüÃǵÄÏÞÖÆ·ûºÍ·µ»ØÀàÐÍ¡£
Õâ¸ö³ÌÐòʹÓà Class.forName ÔØÈëÖ¸¶¨µÄÀ࣬Ȼºóµ÷Óà get
Ïà¹ØÎĵµ£º
ÏÈÉùÃ÷һϣ¬ÌâÄ¿Ô³öÓÚ£ºhttp://gocom.primeton.com/modules/newbb/item60284_60284.htm
JVMÊÇJava³ÌÐòµÄÔËÐл·¾³£¬Òò´Ë¶ÔÓÚJVMµÄÕÆÎÕÓÐÖúÓÚÀí½âJava³ÌÐòµÄÖ´ÐÐÒÔ¼°±àд£¬ÓÈÆäÊÇÔËÐÐʱÅöµ½µÄһЩ¹îÒìÎÊÌ⣬ÄÇôÔõôÑùÄÜ¿¼²ì×Ô¼º¶ÔÓÚJVM¹Ø¼ü֪ʶµãµÄÕÆÎÕÇé¿ö£¬°ïÖúѧϰJVM»úÖÆÄØ£¬ÔÚÕâƪblogÖÐÀ´Ì½ÌÖÏ¡£
¶ÔÓÚJava³ÌÐò¶øÑ ......
ListenerÊÇServletµÄ¼àÌýÆ÷£¬Ëü¿ÉÒÔ¼àÌý¿Í»§¶ËµÄÇëÇó¡¢·þÎñ¶ËµÄ²Ù×÷µÈ¡££¨Í¨¹ý¼àÌýÆ÷£¬¿ÉÒÔ×Ô¶¯¼¤·¢Ò»Ð©²Ù×÷£¬±ÈÈç¼àÌýÔÚÏßµÄÓû§µÄÊýÁ¿¡£µ±Ôö¼ÓÒ»¸öHttpSessionʱ£¬¾Í¼¤·¢
sessionCreated(HttpSessionEvent se)·½·¨£¬ÕâÑù¾Í¿ÉÒÔ¸øÔÚÏßÈËÊý¼Ó1¡££©
Servlet ¼àÌýÆ÷ÓÃÓÚ¼àÌýһЩÖØҪʼþµÄ·¢Éú£¬¼àÌýÆ÷¶ÔÏóÔÚÊÂÇé·¢ÉúÇ°¡¢·¢ ......
һλIDΪultimusµÄ³ÌÐòÔ±¿ª·¢ÁËÒ»ÖÖÃûΪanicµÄÐÂÓïÑÔ£¬½üÈÕÒýÆðÒµ½ç¹Ø×¢¡£¸ù¾ÝGoogle CodeÉϸÃÏîÄ¿µÄ¼ò½é£¬¸ÃÓïÑÔµÄÕýʽÃû³ÆÊÇANI£¬anicÊÇÕâÖÖÓïÑԵIJο¼ÊµÏÖ¡£
ANIÊÇÒ»ÖÖʵÑéÐÔ¡¢¸ßÐÔÄÜ¡¢¾²Ì¬°²È«¡¢ÍêÈ«Òþº¬Ö§³Ö²¢ÐС¢ÃæÏò¶ÔÏóµÄͨÓÃÊý¾ÝÁ÷±à³ÌÓïÑÔ¡£
anicÓÃGNU¹¤¾ßÁ´Ð´³É£¬Òò´Ë¿ÉÒÆÖ²ÐԺܺ㬿ÉÒÔÔËÐÐÓÚËùÓÐÖ÷Á÷²Ù×÷ϵ ......
1¡¢ ¶ÔÏóµÄ³õʼ»¯
(1) ·Ç¾²Ì¬¶ÔÏóµÄ³õʼ»¯
ÔÚ´´½¨¶ÔÏóʱ£¬¶ÔÏóËùÔÚÀàµÄËùÓÐÊý¾Ý³ÉÔ±»áÊ×ÏȽøÐгõʼ»¯¡£
»ù±¾ÀàÐÍ£ºintÐÍ£¬³õʼ»¯Îª0¡£
Èç¹ûΪ¶ÔÏó£ºÕâЩ¶ÔÏó»á°´Ë³Ðò³õʼ»¯¡£
¡ùÔÚËùÓÐÀà³ÉÔ±³õʼ»¯Íê³ÉÖ®ºó£¬²Åµ÷Óñ¾ÀàµÄ¹¹Ôì·½·¨´´½¨¶ÔÏó¡£
¹¹Ôì·½·¨µÄ×÷ÓþÍÊdzõʼ»¯¡£
(2) ¾²Ì¬¶ÔÏóµÄ³õʼ»¯
³ÌÐòÖÐÖ÷ÀàµÄ ......