DANCE WITH JAVA

          開發(fā)出高質(zhì)量的系統(tǒng)

          常用鏈接

          統(tǒng)計(jì)

          積分與排名

          好友之家

          最新評(píng)論

          調(diào)用java的私有方法

          package base;
          ?
          import java.lang.reflect.Method;
          public class PrivateTestCall {
          ?
          ?/**
          ? * @param args
          ? */
          ?public static void main(String[] args) {
          ??// TODO Auto-generated method stub
          ??try{
          ???//method one
          ???Method m=PrivateTest.class.getDeclaredMethod("print", new Class[]{});
          ???m.setAccessible(true);
          ???m.invoke(new PrivateTest(), new Object[]{});
          ???//method two
          ???PrivateTest privateTest=new PrivateTest();
          ???Method m1=privateTest.getClass().getMethod("print2", null);
          ???m1.setAccessible(true);
          ???m1.invoke(privateTest, null);
          ???//method three
          ???Method m2=PrivateTest.class.getMethod("print2", null);
          ???m2.setAccessible(true);
          ???m2.invoke(new PrivateTest(), null);
          ??}catch(Exception e){
          ???e.printStackTrace();
          ??}
          ?}
          ?
          }

          ?

          package base;
          ?
          public class PrivateTest {
          ?private void print(){
          ??System.out.println("in private method");
          ?}
          ?public void print2(){
          ??System.out.println("in public method");
          ?}
          }

          posted on 2006-09-20 21:18 dreamstone 閱讀(753) 評(píng)論(0)  編輯  收藏 所屬分類: jdk相關(guān)

          主站蜘蛛池模板: 聊城市| 历史| 赤峰市| 嘉鱼县| 基隆市| 武夷山市| 江口县| 茂名市| 洪雅县| 广东省| 嵊州市| 交口县| 柯坪县| 白朗县| 南安市| 巴林右旗| 伊宁市| 龙口市| 尖扎县| 荆州市| 博野县| 富民县| 绥棱县| 巴中市| 乌苏市| 平阳县| 定陶县| 图木舒克市| 南乐县| 千阳县| 阳城县| 平阳县| 青阳县| 正阳县| 长垣县| 莱西市| 吉林省| 大庆市| 河间市| 融水| 习水县|