Java·´Éä2
1.2.3.ConstructorÀࣺ
ConstructorÀà´ú±íij¸öÀàµÄÒ»¸ö¹¹Ôì·½·¨¡£
µÃµ½Ä³¸öÀàËùÓеĹ¹Ôì·½·¨£º
Constructor[] constructor = Class.forName(“java.lang.String”).getConstructor();
µÃµ½Ä³Ò»¸ö¹¹Ôì·½·¨£º
Constructor constructor =
Class.forName(“java.lang.String”).getConstructor(StringBuffer.class);
´´½¨ÊµÀý¶ÔÏó£ºString str2 = (String)constructor1.newInstance(new StringBuffer("abc"));
1.2.4.FieldÀࣺ
Field´ú±íij¸öÀàµÄÒ»¸ö³ÉÔ±±äÁ¿¡£ÌṩÓйØÀà»ò½Ó¿ÚµÄÊôÐÔµÄÐÅÏ¢£¬ÒÔ¼°¶ÔËüµÄ¶¯Ì¬·ÃÎÊȨÏÞ¡£·´ÉäµÄ×ֶοÉÄÜÊÇÒ»¸öÀࣨ¾²Ì¬£©ÊôÐÔ»òʵÀýÊôÐÔ£¬¼òµ¥µÄÀí½â¿ÉÒÔ°ÑËü¿´³ÉÒ»¸ö·â×°·´ÉäÀàµÄÊôÐÔµÄÀà¡£
public void setAccessible(boolean flag)
ÉèÖÃÊÇ·ñÓÐȨÏÞ·ÃÎÊ·´ÉäÀàÖеÄ˽ÓÐÊôÐԵģ¬Ö»ÓÐÉèÖÃΪtrueʱ²Å¿ÉÒÔ·ÃÎÊ£¬Ä¬ÈÏΪfalse¡£
public void set(Object obj,Object value)
ÉèÖÃÖ¸¶¨ÊôÐÔµÄÖµ¡£
public Object get(Object obj)
µÃµ½ÊôÐÔµÄÖµ
ÎÊÌ⣺µÃµ½µÄField¶ÔÏóÊǶÔÓ¦µ½ÀàÉÏÃæµÄ³ÉÔ±±äÁ¿£¬»¹ÊǶÔÓ¦µ½¶ÔÏóÉϵijÉÔ±±äÁ¿£¿ÀàÖ»ÓÐÒ»¸ö£¬¶ø¸ÃÀàµÄʵÀý¶ÔÏóÓжà¸ö£¬Èç¹ûÊÇÓë¶ÔÏó¹ØÁª£¬ÄǹØÁªµÄÊÇÄĸö¶ÔÏóÄØ£¿
²âÊÔ´úÂ룺
public class ReflectPoint {
private int x;
public int y;
public ReflectPoint(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}
²âÊÔ´úÂ룺
ReflectPoint pt1 = new ReflectPoint(3,5);
Field fieldY = pt1.getClass().getField("y");
//fieldYµÄÖµÊǶàÉÙ£¿ÊÇ5,´í£¡fieldY²»ÊǶÔÏóÉíÉϵıäÁ
Ïà¹ØÎĵµ£º
µÝ¹éº¯ÊýÖ®JAVAÑÝÒï
µÝ¹éº¯ÊýÖ®JAVAÑÝÒï
1¡¢µÝ¹éº¯ÊýµÄ¶¨Ò壺
´ð£ºµÝ¹éº¯Êý¼´×Ôµ÷Óú¯Êý£¬ÔÚº¯ÊýÌåÄÚÖ±½Ó»ò¼ä½ÓµÄµ÷ÓÃ×Ô¼º£¬¼´º¯ÊýµÄǶÌ×ÊǺ¯Êý±¾Éí¡£
2¡¢µÝ¹é·½Ê½£ºµÝ¹éµ÷ÓÃÓÐÖ±½ÓµÝ¹éºÍ¼ä½ÓµÝ¹éÁ½ÖÖ·½Ê½¡£
A£ºÖ±½ÓµÝ¹é£ºÔÚº¯ÊýÖгöÏÖµ÷Óú¯Êý±¾Éí¡£
ʾÀý1£ºÏÂÃæ´úÂëÇóì³²¨ÄÇÆõÊýÁеÚnÏ쳲¨ÄÇÆõÊýÁеÚÒ»ºÍµÚ¶þÏ ......
µÚÒ»£¬Ì¸Ì¸final, finally, finalizeµÄÇø±ð¡£
×î³£±»Îʵ½¡£
µÚ¶þ£¬Anonymous Inner Class (ÄäÃûÄÚ²¿Àà) ÊÇ·ñ¿ÉÒÔextends(¼Ì³Ð)ÆäËüÀ࣬ÊÇ·ñ¿ÉÒÔimplements(ʵÏÖ)interface(½Ó¿Ú)?
µÚÈý£¬Static Nested Class ºÍ Inner ClassµÄ²»Í¬£¬ËµµÃÔ½¶àÔ½ºÃ(ÃæÊÔÌâÓеĺÜÁýͳ)¡£
µÚËÄ£¬&ºÍ&&µÄÇø±ð¡£
Õâ¸öÎʵúÜÉÙ¡£
......
JAVAÏà¹Ø»ù´¡ÖªÊ¶
1¡¢ÃæÏò¶ÔÏóµÄÌØÕ÷ÓÐÄÄЩ·½Ãæ
1.³éÏó£º
³éÏó¾ÍÊǺöÂÔÒ»¸öÖ÷ÌâÖÐÓ뵱ǰĿ±êÎ޹صÄÄÇЩ·½Ã棬ÒÔ±ã¸ü³ä·ÖµØ×¢ÒâÓ뵱ǰĿ±êÓйصķ½Ãæ¡£³éÏó²¢²»´òËãÁ˽âÈ«²¿ÎÊÌ⣬¶øÖ»ÊÇÑ¡ÔñÆäÖеÄÒ»²¿·Ö£¬ÔÝʱ²»Óò¿·Öϸ½Ú¡£³éÏó°üÀ¨Á½¸ö·½Ã棬һÊǹý³Ì³éÏ󣬶þÊÇÊý¾Ý³éÏó¡£
2.¼Ì³Ð£º
¼Ì³ÐÊÇÒ»ÖÖÁª½ ......
.classÆäʵÊÇÔÚjavaÔËÐÐʱ¾Í¼ÓÔØ½øÈ¥µÄ
getClass()ÊÇÔËÐгÌÐòʱ¶¯Ì¬¼ÓÔØµÄ
ÏÂÃæÒÔÀý×Ó˵Ã÷:
Ê×ÏȽ¨Ò»¸ö»ùÀàBaseclass
package classyongfa;
public class Baseclass {
private String height;
public String getHeight()
{
return height;
}
public void setHeight(String height)
{
&n ......
package javatest_danny;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
public class pipeStreamTest {
public static void main(String[] args) {
try
{
&nbs ......