Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

java¶¯Ì¬´úÀíÀà

 
Java¶¯Ì¬´úÀíÀàλÓÚjava.lang.reflect°üÏ£¬Ò»°ãÖ÷ÒªÉæ¼°µ½ÒÔÏÂÁ½¸öÀࣺ
(1)Interface InvocationHandler£º¸Ã½Ó¿ÚÖнö¶¨ÒåÁËÒ»¸ö·½·¨
§public object invoke(Object obj,Method method, Object[] args)
ÔÚʵ¼ÊʹÓÃʱ£¬µÚÒ»¸ö²ÎÊýobjÒ»°ãÊÇÖ¸´úÀíÀ࣬methodÊDZ»´úÀíµÄ·½·¨£¬ÈçÉÏÀýÖеÄrequest()£¬argsΪ¸Ã·½·¨µÄ²ÎÊýÊý×é¡£ Õâ¸ö³éÏó·½·¨ÔÚ´úÀíÀàÖж¯Ì¬ÊµÏÖ¡£
(2)Proxy£º¸ÃÀ༴Ϊ¶¯Ì¬´úÀíÀ࣬×÷ÓÃÀàËÆÓÚÉÏÀýÖеÄProxySubject£¬ÆäÖÐÖ÷Òª°üº¬ÒÔÏÂÄÚÈÝ
 
 
 
protected Proxy(InvocationHandler h)£º¹¹Ô캯Êý£¬ÓÃÓÚ¸øÄÚ²¿µÄh¸³Öµ¡£
static Class getProxyClass (ClassLoader loader, Class[] interfaces)£º»ñµÃÒ»¸ö´úÀíÀ࣬ÆäÖÐloaderÊÇÀà×°ÔØÆ÷£¬interfacesÊÇÕæʵÀàËùÓµÓеÄÈ«²¿½Ó¿ÚµÄÊý×é¡£
static Object newProxyInstance(ClassLoader loader, Class[] interfaces, InvocationHandler h)£º·µ»Ø´úÀíÀàµÄÒ»¸öʵÀý£¬·µ»ØºóµÄ´úÀíÀà¿ÉÒÔµ±×÷±»´úÀíÀàʹÓÃ(¿ÉʹÓñ»´úÀíÀàµÄÔÚSubject½Ó¿ÚÖÐÉùÃ÷¹ýµÄ·½·¨)
 
ËùνDynamic ProxyÊÇÕâÑùÒ»ÖÖclass£ºËüÊÇÔÚÔËÐÐʱÉú³ÉµÄclass£¬ÔÚÉú³ÉËüʱÄã±ØÐëÌṩһ×éinterface¸øËü£¬È»ºó¸Ãclass¾ÍÐû³ÆËüʵÏÖÁËÕâЩ interface¡£Ä㵱Ȼ¿ÉÒ԰ѸÃclassµÄʵÀýµ±×÷ÕâЩinterfaceÖеÄÈκÎÒ»¸öÀ´Óᣵ±È»£¬Õâ¸öDynamic ProxyÆäʵ¾ÍÊÇÒ»¸öProxy£¬Ëü²»»áÌæÄã×÷ʵÖÊÐԵŤ×÷£¬ÔÚÉú³ÉËüµÄʵÀýʱÄã±ØÐëÌṩһ¸öhandler£¬ÓÉËü½Ó¹Üʵ¼ÊµÄ¹¤×÷
 
ÔÚʹÓö¯Ì¬´úÀíÀàʱ£¬ÎÒÃDZØÐëʵÏÖInvocationHandler½Ó¿Ú
²Î¼û³ÌÐò Subject.java
²Î¼û³ÌÐò RealSubject.java
²Î¼û³ÌÐò DynamicSubject.java
²Î¼û³ÌÐò Client.java
package com.langsin.dynamicproxy;
//³éÏó½ÇÉ«(֮ǰÊdzéÏóÀ࣬´Ë´¦Ó¦¸ÄΪ½Ó¿Ú)£º
public interface Subject
{
abstract public void request();
}
package com.langsin.dynamicproxy;
//¾ßÌå½ÇÉ«(¾Ö³¤)
public class RealSubject implements Subject
{
public RealSubject()
{
}
public void request()
{
System.out.println("from real subject.");
}
}
package com.langsin.dynamicproxy;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
//´úÀí´¦ÀíÆ÷(ÃØÊé)
/**
* ¸Ã´úÀíÀàµÄÄÚ²¿ÊôÐÔΪObjectÀ࣬ʵ¼ÊʹÓÃʱͨ¹ý¸ÃÀàµÄ¹¹Ô캯ÊýDynamicSubject(Object obj)¶ÔÆ


Ïà¹ØÎĵµ£º

java project ת³Édynamic web project

תÔØ×Ô£ºhttp://blog.csdn.net/seaward/archive/2008/11/26/3376511.aspx
ÓÃgoogleÕÒµ½¹ýÀÏÍâдµÄÏà¹ØµÄÎÄÕ£¬µ«ÊDz»ÍêÕû¡£¸ù¾Ý×Ô¼ºµÄʵ¼ùÖØÐÂдһ¸ö¡£
¼ÙÉ裺ÎÒÃÇÏÖÓÐÒ»¸öjava project½Ð×öoldWebApp£¬Ò»¸öDynamic Web Project½Ð×ödynaWebApp¡£
1¡¢ÔÚoldWebAppµÄ¸ùĿ¼ÏÂÕÒµ½²¢´ò¿ª.projectÎļþ£¬Ð޸ijÉ
<?xml ver ......

Lombok Ïû³ýJavaµÄÈß³¤


  LombokÊÇÒ»¸ö¿ªÔ´ÏîÄ¿£¬¿ÉÒÔÓÃÀ´Ïû³ýJava´úÂëµÄÈß³¤
  Ïêϸ½éÉܲο´http://www.ibm.com/developerworks/opensource/library/os-lombok/index.html
  ÏÂÃæ½éÉÜLombokÈçºÎÏû³ýJava´úÂëµÄÈß³¤¡£
1.      Ê×ÏÈÈ¥http://projectlombok.org/. ÏÂÔØlombok.jar °ü
2.  & ......

Ϊʲô´ó¶àÊý´óÐÍÍøÕ¾²»ÊÇÓÃJavaдµÄ£¿

×÷Ϊһ¸öJava³ÌÐòÔ±£¬ÎÒÃdz£³£»áÆĸÐ×ÔºÀµØ˵£º½ðÈÚÐÐÒµµÄ´óϵͳһ°ã¶¼ÊÇÓÃJavaдµÄ¡£ÓÐÌ«¶àÀíÓÉÈÃÎÒÃÇÏàÐÅ£¬JavaÔÚÆóÒµ¼¶Ó¦ÓÃÕâ¿é£¬ÆðמÙ×ãÇáÖصÄ×÷Óá£È»¶ø£¬ÊÂʵ¹ûÕæÈç´ËÂ𣿽ðÈÚÐÐÒµ»òÐíÊÇÄÇÑù£¬¿ÉÊÇÏñGoogle¡¢AmazonÕâÑùµÄ´óÐÍÍøÕ¾ÄØ£¿Ãæ¶ÔÕâÑùµÄÒÉÎÊ£¬ÔÚ·Ö²¼Ê½Ó¦Óá¢CORBA¡¢JINI¡¢J2EE¡¢Íø¸ñºÍSOAÁìÓò£¬ÓÐ×Å10¶àÄê¾­ ......

Java Éè¼Æ¼Ü¹¹


Ŀ¼
ÕªÒª ……………………………………………………………………2
ÎÄÏ××ÛÊö ……………………&h ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ