public class ClassA{
? private long Rkey;
? public long getRkey() {
??????? return Rkey;
??? }
? public void setRkey(long rkey) {
??????? this.Rkey = rkey;
??? }???????
}
public class ClassA{
? private long Rkey;
? public long getRkey() {
??????? return Rkey;
??? }
? public void setRkey(long rkey) {
??????? this.Rkey = rkey;
??? }???????
}
-----------------------------
public class Assistant {
? public static final String CLASSA= "classA";
?public static Object create(String str) {////////////返射機制的方法
??? Object cf=null;
??? try {
????? cf = (Object)Class.forName(str).newInstance();
??? }
??? catch (ClassNotFoundException ex) {
????? ex.printStackTrace();
??? }
??? catch (IllegalAccessException ex) {
????? ex.printStackTrace();
??? }
??? catch (InstantiationException ex) {
????? ex.printStackTrace();
??? }
??? return cf;
? }
調用:
classA cc=(classA)Assistant.create(Assistant.CLASSA);
cc.setRkey(rkey);
cc.getRkey();
posted on 2006-04-14 16:14
有貓相伴的日子 閱讀(354)
評論(0) 編輯 收藏 所屬分類:
j2ee