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¸öÀàÖÐ
Ïà¹ØÎĵµ£º
File f=new File("DerectoryName");
String []results=f.list();
import java.io.*;
¡¡¡¡public class listFile
¡¡¡¡{ &nb ......
Observer
Intent
Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
How to
Subject
knows its observers. Any number of Observer objects may observe a subject.
provides an in ......
ѧϰJavaÖµ´«µÝ·½·¨-Î人±±´óÇàÄñ
¡¡¡¡Öµ´«µÝÊÇÔÚÒ»¸öº¯ÊýÖУ¬µ÷ÓÃÁíÍâÒ»¸öº¯Êý£¬ÆäÖк¬ÓвÎÊý´«µÝµÄÇé¿ö¡£ÍùÍùÖµ´«µÝ¾ÍÊÇ°ÑÊý¾Ý´«µÝµ½ÁíÍâÒ»¸öº¯ÊýÖнøÐнøÒ»²½´¦Àí£¬ÒÔ¸üÇå³þµØÏÔʾº¯ÊýµÄ±í´ïÒâ˼¡£ÔÚº¯Êýµ÷ÓõÄʱºò»áÓÐÊý¾Ý´«µÝ£¬Í¬ÑùÒª¿¼ÂÇÐβκÍʵ²ÎµÄÎÊÌ⣬ÈçÏÂÃæµÄÒ»¸ö³ÌÐò£º
¡¡¡¡on error resume next ShockMode ......
ÊÖÉÏÒ»¸öÏîÄ¿ÐèҪͨ¹ýusb¿ÚÈ¥¶ÁÈ¡usbkeyµÄÐÅÏ¢£¬³§¼ÒÌṩµÄÖ»ÓÐC/C++µÄ½Ó¿Ú£¬¶øÖ÷Ó¦ÓÃÊÇjavaµÄ£¬ËùÒÔÐèҪʹÓÃjavaÈ¥µ÷Óö¯Ì¬Á´½Ó¿â£¬ËùÒÔ»¨Á˵ãʱ¼äÑо¿ÁËÏÂJNI¼¼Êõ£¬jdk¶ÔJNI¼¼Êõ·â×°µÃºÜµ½Î»£¬Ê¹ÓÃÆðÀ´·Ç³£¼òµ¥£¬JNI¼¼Êõ×î¹Ø¼ü»¹ÊÇÔÚÓÚjniÊý¾ÝÀàÐͺͱ¾µØÊý¾ÝÀàÐ͵Äת»»¡£Ïȼòµ¥ÂÞÁÐÏÂJNIµ ......
ѧϰJavaÀàµÄÊôÐÔ-Î人±±´óÇàÄñ
¡¡¡¡Public¡¢private¡¢protectedÏÔʾÁËÈýÖÖÀàÖеÄÊôÐԺͷþÎñµÄÀàÐÍ£¬publicÊÇ¿ÉÒÔËæÒâ·ÃÎʵġ¢privateÊÇÍâ½ç²»ÄÜ·ÃÎʵÄ(ÏÔʾÁËÊý¾ÝµÄ·â×°ÐÔ)¡¢protected˵Ã÷Êý¾ÝÊÇÊܱ£»¤µÄ¡£ÏÂÃæ¾ÍÀ´Ïêϸ½²ÊöÒ»ÏÂÕâÈý¸ö¾¿¾¹ÓÐʲôÇø±ð¡£
¡¡¡¡Ê×ÏÈÒªÁ˽âһϰüµÄ¸ÅÄî¡£ÓÐÈô¸É¸öÀ࣬ËüÃÇÏ໥֮¼äÓÐÒ»¶¨µÄ¹ØÏ ......