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 ÔØÈëÖ¸¶¨µÄÀ࣬Ȼºóµ÷Óà getDeclaredMethods À´»ñÈ¡Õâ¸öÀàÖж¨ÒåÁ˵ķ½·¨ÁÐ±í¡£java.lang.reflect.Methods ÊÇÓÃÀ´ÃèÊöij¸öÀàÖе¥¸ö·½·¨µÄÒ»¸öÀà¡£
2.¿ªÊ¼Ê¹Óà Reflection
Ó
Ïà¹ØÎĵµ£º
ÕâÁ½Ìì×öÍêÁËÒÔÇ°£¬CRMÏîÄ¿ÖУ¬Éè¼ÆȨÏÞÕâ¿ìµÄ´úÂ룬½ö¹©´ó¼Òѧϰ²Î¿¼¡£
±¾È¨ÏÞ¹ÜÀí²¿·ÖÉè¼ÆÈý²¿·Ö£º
µÚÒ»²¿·Ö Êý¾Ý¿â²¿·Ö
µÚ¶þ²¿·Ö ȨÏÞÀà
µÚÈý²¿·Ö ·ÖÅäȨÏÞ²¿·Ö
µÚËIJ¿·Ö Ò³Ãæ¿ØÖƲ¿·Ö
ÔÚÕâÀïÎÒÖ÷ÒªÉè¼ÆºóÈý²¿·ÖÔÂ룺
ȨÏÞÀàÉè¼ÆÔÂ룺
package com.qizhi.common;
/**
* È«¾Ö³£Á¿
*
&nbs ......
×Ô¶¨Òå±êÇ©£¬±êÇ©´¦ÀíÆ÷Àࣺ
PrivilegeTag.JavaÓÐȨÏÞµÄÀàÉè¼Æ£º
package com.qizhi.tags.bean;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.tagext.TagSupport;
import com.qizhi.entity.Roleright;
import com.qizh ......
ÓÐÁ½ÖÖʵÏÖ·½·¨£¬·Ö±ðÊǼ̳ÐThreadÀàÓëʵÏÖRunnable½Ó¿Ú
ÓÃsynchronized¹Ø¼ü×ÖÐÞÊÎͬ²½·½·¨
·´¶ÔʹÓÃstop()£¬ÊÇÒòΪËü²»°²È«¡£Ëü»á½â³ýÓÉÏ̻߳ñÈ¡µÄËùÓÐËø¶¨£¬¶øÇÒÈç¹û¶ÔÏó´¦ÓÚÒ»ÖÖ²»Á¬¹á״̬£¬ÄÇôÆäËûÏß³ÌÄÜÔÚÄÇÖÖ״̬ϼì²éºÍÐÞ¸ÄËüÃÇ¡£½á¹ûºÜÄѼì²é³öÕæÕýµÄÎÊÌâËùÔÚ¡£suspend()·½·¨ÈÝÒ×·¢ÉúËÀËø¡£µ÷ÓÃsuspend()µÄʱºò ......
ÊÂÎñµÄÌØÐÔ£º
1) Ô×ÓÐÔ£¨atomicity£©£ºÊÂÎñÊÇÊý¾Ý¿âµÄÂß¼¹¤×÷µ¥Î»£¬¶øÇÒÊDZØÐëÊÇÔ×Ó¹¤×÷µ¥Î»£¬¶ÔÓÚÆäÊý¾ÝÐ޸ģ¬ÒªÃ´È«²¿Ö´ÐУ¬ÒªÃ´È«²¿²»Ö´ÐС£
2) Ò»ÖÂÐÔ£¨consistency£©£ºÊÂÎñÔÚÍê³Éʱ£¬±ØÐëÊÇËùÓеÄÊý¾Ý¶¼±£³ÖÒ»ÖÂ״̬¡£ÔÚÏà¹ØÊý¾Ý¿âÖУ¬ËùÓйæÔò¶¼±ØÐëÓ¦ÓÃÓÚÊÂÎñµÄÐ޸ģ¬ÒÔ±£³ÖËùÓÐÊý¾ÝµÄÍêÕûÐÔ¡£
3)&n ......