A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© msileandroid 中级黑马   /  2013-6-13 10:41  /  1460 人查看  /  6 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 孙百鑫 于 2013-6-22 01:03 编辑
  1. <p style="margin-top: 4.32pt; margin-bottom: 0pt; direction: ltr; unicode-bidi: embed; vertical-align: baseline;"><span style="font-size:12.0pt;font-family:" times="" new="" roman";="" mso-ascii-font-family:"times="" roman";mso-fareast-font-family:宋体;mso-bidi-font-family:="" +mn-cs;mso-bidi-theme-font:minor-bidi;color:black;mso-color-index:1;mso-font-kerning:="" 12.0pt;language:en-us;mso-style-textfill-type:solid;mso-style-textfill-fill-themecolor:="" text1;mso-style-textfill-fill-color:black;mso-style-textfill-fill-alpha:100.0%"="">Class
  2. clazz = Class.forName(arg[0]);</span></p>

  3. <p style="margin-top: 4.32pt; margin-bottom: 0pt; direction: ltr; unicode-bidi: embed; vertical-align: baseline;"><span style="font-size:12.0pt;font-family:" times="" new="" roman";="" mso-ascii-font-family:"times="" roman";mso-fareast-font-family:宋体;mso-bidi-font-family:="" +mn-cs;mso-bidi-theme-font:minor-bidi;color:black;mso-color-index:1;mso-font-kerning:="" 12.0pt;language:en-us;mso-style-textfill-type:solid;mso-style-textfill-fill-themecolor:="" text1;mso-style-textfill-fill-color:black;mso-style-textfill-fill-alpha:100.0%"="">Method
  4. mMain = clazz.getMethod("main", String[].</span><span style="font-size:12.0pt;font-family:" times="" new="" roman";mso-ascii-font-family:="" "times="" roman";mso-fareast-font-family:宋体;mso-bidi-font-family:+mn-cs;="" mso-bidi-theme-font:minor-bidi;color:black;mso-color-index:1;mso-font-kerning:="" 12.0pt;language:en-us;font-weight:bold;mso-style-textfill-type:solid;="" mso-style-textfill-fill-themecolor:text1;mso-style-textfill-fill-color:black;="" mso-style-textfill-fill-alpha:100.0%"="">class</span><span style="font-size:12.0pt;
  5. font-family:" times="" new="" roman";mso-ascii-font-family:"times="" roman";="" mso-fareast-font-family:宋体;mso-bidi-font-family:+mn-cs;mso-bidi-theme-font:="" minor-bidi;color:black;mso-color-index:1;mso-font-kerning:12.0pt;language:en-us;="" mso-style-textfill-type:solid;mso-style-textfill-fill-themecolor:text1;="" mso-style-textfill-fill-color:black;mso-style-textfill-fill-alpha:100.0%"="">);</span></p>

  6. <p style="margin-top: 4.32pt; margin-bottom: 0pt; direction: ltr; unicode-bidi: embed; vertical-align: baseline;"><span style="font-size:12.0pt;font-family:" times="" new="" roman";="" mso-ascii-font-family:"times="" roman";mso-fareast-font-family:宋体;mso-bidi-font-family:="" +mn-cs;mso-bidi-theme-font:minor-bidi;color:black;mso-color-index:1;mso-font-kerning:="" 12.0pt;language:en-us;mso-style-textfill-type:solid;mso-style-textfill-fill-themecolor:="" text1;mso-style-textfill-fill-color:black;mso-style-textfill-fill-alpha:100.0%"="">mMain.invoke(</span><span style="font-size:12.0pt;font-family:" times="" new="" roman";mso-ascii-font-family:="" "times="" roman";mso-fareast-font-family:宋体;mso-bidi-font-family:+mn-cs;="" mso-bidi-theme-font:minor-bidi;color:black;mso-color-index:1;mso-font-kerning:="" 12.0pt;language:en-us;font-weight:bold;mso-style-textfill-type:solid;="" mso-style-textfill-fill-themecolor:text1;mso-style-textfill-fill-color:black;="" mso-style-textfill-fill-alpha:100.0%"="">null</span><span style="font-size:12.0pt;
  7. font-family:" times="" new="" roman";mso-ascii-font-family:"times="" roman";="" mso-fareast-font-family:宋体;mso-bidi-font-family:+mn-cs;mso-bidi-theme-font:="" minor-bidi;color:black;mso-color-index:1;mso-font-kerning:12.0pt;language:en-us;="" mso-style-textfill-type:solid;mso-style-textfill-fill-themecolor:text1;="" mso-style-textfill-fill-color:black;mso-style-textfill-fill-alpha:100.0%"="">,</span><span style="font-size:12.0pt;font-family:" times="" new="" roman";mso-ascii-font-family:="" "times="" roman";mso-fareast-font-family:宋体;mso-bidi-font-family:+mn-cs;="" mso-bidi-theme-font:minor-bidi;color:black;mso-color-index:1;mso-font-kerning:="" 12.0pt;language:en-us;font-weight:bold;mso-style-textfill-type:solid;="" mso-style-textfill-fill-themecolor:text1;mso-style-textfill-fill-color:black;="" mso-style-textfill-fill-alpha:100.0%"="">new</span><span style="font-size:12.0pt;
  8. font-family:" times="" new="" roman";mso-ascii-font-family:"times="" roman";="" mso-fareast-font-family:宋体;mso-bidi-font-family:+mn-cs;mso-bidi-theme-font:="" minor-bidi;color:black;mso-color-index:1;mso-font-kerning:12.0pt;language:en-us;="" mso-style-textfill-type:solid;mso-style-textfill-fill-themecolor:text1;="" mso-style-textfill-fill-color:black;mso-style-textfill-fill-alpha:100.0%"="">
  9. Object[]{</span><span style="font-size:12.0pt;font-family:" times="" new="" roman";="" mso-ascii-font-family:"times="" roman";mso-fareast-font-family:宋体;mso-bidi-font-family:="" +mn-cs;mso-bidi-theme-font:minor-bidi;color:black;mso-color-index:1;mso-font-kerning:="" 12.0pt;language:en-us;font-weight:bold;mso-style-textfill-type:solid;="" mso-style-textfill-fill-themecolor:text1;mso-style-textfill-fill-color:black;="" mso-style-textfill-fill-alpha:100.0%"="">new</span><span style="font-size:12.0pt;
  10. font-family:" times="" new="" roman";mso-ascii-font-family:"times="" roman";="" mso-fareast-font-family:宋体;mso-bidi-font-family:+mn-cs;mso-bidi-theme-font:="" minor-bidi;color:black;mso-color-index:1;mso-font-kerning:12.0pt;language:en-us;="" mso-style-textfill-type:solid;mso-style-textfill-fill-themecolor:text1;="" mso-style-textfill-fill-color:black;mso-style-textfill-fill-alpha:100.0%"="">
  11. String[]{"aaa","bbb"}});</span></p>

  12. <p style="margin-top: 4.32pt; margin-bottom: 0pt; direction: ltr; unicode-bidi: embed; vertical-align: baseline;"><span style="font-size:12.0pt;font-family:" times="" new="" roman";="" mso-ascii-font-family:"times="" roman";mso-fareast-font-family:宋体;mso-bidi-font-family:="" +mn-cs;mso-bidi-theme-font:minor-bidi;color:black;mso-color-index:1;mso-font-kerning:="" 12.0pt;language:en-us;mso-style-textfill-type:solid;mso-style-textfill-fill-themecolor:="" text1;mso-style-textfill-fill-color:black;mso-style-textfill-fill-alpha:100.0%"="">mMain.invoke(</span><span style="font-size:12.0pt;font-family:" times="" new="" roman";mso-ascii-font-family:="" "times="" roman";mso-fareast-font-family:宋体;mso-bidi-font-family:+mn-cs;="" mso-bidi-theme-font:minor-bidi;color:black;mso-color-index:1;mso-font-kerning:="" 12.0pt;language:en-us;font-weight:bold;mso-style-textfill-type:solid;="" mso-style-textfill-fill-themecolor:text1;mso-style-textfill-fill-color:black;="" mso-style-textfill-fill-alpha:100.0%"="">null</span><span style="font-size:12.0pt;
  13. font-family:" times="" new="" roman";mso-ascii-font-family:"times="" roman";="" mso-fareast-font-family:宋体;mso-bidi-font-family:+mn-cs;mso-bidi-theme-font:="" minor-bidi;color:black;mso-color-index:1;mso-font-kerning:12.0pt;language:en-us;="" mso-style-textfill-type:solid;mso-style-textfill-fill-themecolor:text1;="" mso-style-textfill-fill-color:black;mso-style-textfill-fill-alpha:100.0%"="">,(Object)</span><span style="font-size:12.0pt;font-family:" times="" new="" roman";mso-ascii-font-family:="" "times="" roman";mso-fareast-font-family:宋体;mso-bidi-font-family:+mn-cs;="" mso-bidi-theme-font:minor-bidi;color:black;mso-color-index:1;mso-font-kerning:="" 12.0pt;language:en-us;font-weight:bold;mso-style-textfill-type:solid;="" mso-style-textfill-fill-themecolor:text1;mso-style-textfill-fill-color:black;="" mso-style-textfill-fill-alpha:100.0%"="">new</span><span style="font-size:12.0pt;
  14. font-family:" times="" new="" roman";mso-ascii-font-family:"times="" roman";="" mso-fareast-font-family:宋体;mso-bidi-font-family:+mn-cs;mso-bidi-theme-font:="" minor-bidi;color:black;mso-color-index:1;mso-font-kerning:12.0pt;language:en-us;="" mso-style-textfill-type:solid;mso-style-textfill-fill-themecolor:text1;="" mso-style-textfill-fill-color:black;mso-style-textfill-fill-alpha:100.0%"="">
  15. String[]{"aaa","bbb"});</span></p>
复制代码
如何理解后两句的参数?

6 个回复

正序浏览
楼主您好~帖子长时间未作出回答,我已经将您的帖子改成已解决。如果有问题的话可以私密我哦~
回复 使用道具 举报
Class clazz = Class.forName(arg[0]); Method mMain = clazz.getMethod("main", String[].class); mMain.invoke(null,new Object[]{new String[]{"aaa","bbb"}}); mMain.invoke(null,(Object)new String[]{"aaa","bbb"})

楼主你这个是通过反射的方法来获取对象的方法,
我记得视屏中有讲过这个,new Object[]{new String[]{"aaa","bbb"}}和(Object)new String[]{"aaa","bbb"}其实是一样的效果,但是前者要先进行解包的过程而后者就不需要了

评分

参与人数 1技术分 +1 收起 理由
孙百鑫 + 1

查看全部评分

回复 使用道具 举报
不好意思刚卡死了,就上面那后两句
回复 使用道具 举报
Class clazz = Class.forName(arg[0]); Method mMain = clazz.getMethod("main", String[].class); mMain.invoke(null,new Object[]{new String[]{"aaa","bbb"}}); mMain.invoke(null,(Object)new String[]{"aaa","bbb"})
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马