{"id":585,"date":"2011-03-16T01:12:58","date_gmt":"2011-03-15T17:12:58","guid":{"rendered":"http:\/\/www.strongd.net\/?p=585"},"modified":"2011-03-16T01:12:58","modified_gmt":"2011-03-15T17:12:58","slug":"%e9%80%9a%e8%bf%87%e5%8f%8d%e5%b0%84%e8%b0%83%e7%94%a8%e5%af%b9%e8%b1%a1%e7%9a%84%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.strongd.net\/?p=585","title":{"rendered":"\u901a\u8fc7\u53cd\u5c04\u8c03\u7528\u5bf9\u8c61\u7684\u65b9\u6cd5"},"content":{"rendered":"<div>\u8fd9\u662f\u4e2a\u6d4b\u8bd5\u7528\u7684\u4f8b\u5b50\uff0c\u901a\u8fc7\u53cd\u5c04\u8c03\u7528\u5bf9\u8c61\u7684\u65b9\u6cd5\u3002<\/div>\n<div>TestRef.java<\/div>\n<div>\n<div><span style=\"color: #0000ff;\">import<\/span> java.lang.reflect.Method;<br \/>\n<span style=\"color: #0000ff;\">import<\/span> java.lang.reflect.InvocationTargetException;<\/p>\n<p><span style=\"color: #008000;\">\/**<br \/>\n* Created by IntelliJ IDEA.<br \/>\n* File: TestRef.java<br \/>\n* User: String<br \/>\n* Date: 2010-3-29 14:48:44<br \/>\n*\/<\/span><br \/>\n<span style=\"color: #0000ff;\">public<\/span> <span style=\"color: #0000ff;\">class<\/span> TestRef {<\/p>\n<p><span style=\"color: #0000ff;\">public<\/span> <span style=\"color: #0000ff;\">static<\/span> <span style=\"color: #0000ff;\">void<\/span> main(String args[])\u00a0<span style=\"color: #0000ff;\">throws<\/span> NoSuchMethodException, IllegalAccessException, InvocationTargetException {<br \/>\nFoo foo =\u00a0<span style=\"color: #0000ff;\">new<\/span> Foo(<span style=\"color: #800000;\">&#8220;\u8fd9\u4e2a\u4e00\u4e2aFoo\u5bf9\u8c61\uff01&#8221;<\/span>);<br \/>\nClass clazz = foo.getClass();<br \/>\nMethod m1 = clazz.getDeclaredMethod(<span style=\"color: #800000;\">&#8220;outInfo&#8221;<\/span>);<br \/>\nMethod m2 = clazz.getDeclaredMethod(<span style=\"color: #800000;\">&#8220;setMsg&#8221;<\/span>, String.<span style=\"color: #0000ff;\">class<\/span>);<br \/>\nMethod m3 = clazz.getDeclaredMethod(<span style=\"color: #800000;\">&#8220;getMsg&#8221;<\/span>);<br \/>\nm1.invoke(foo);<br \/>\nm2.invoke(foo,\u00a0<span style=\"color: #800000;\">&#8220;\u91cd\u65b0\u8bbe\u7f6emsg\u4fe1\u606f\uff01&#8221;<\/span>);<br \/>\nString msg = (String) m3.invoke(foo);<br \/>\nSystem.out.println(msg);<br \/>\n}<br \/>\n}<\/p>\n<p><span style=\"color: #0000ff;\">class<\/span> Foo {<br \/>\n<span style=\"color: #0000ff;\">private<\/span> String msg;<\/p>\n<p><span style=\"color: #0000ff;\">public<\/span> Foo(String msg) {<br \/>\n<span style=\"color: #0000ff;\">this<\/span>.msg = msg;<br \/>\n}<\/p>\n<p><span style=\"color: #0000ff;\">public<\/span> <span style=\"color: #0000ff;\">void<\/span> setMsg(String msg) {<br \/>\n<span style=\"color: #0000ff;\">this<\/span>.msg = msg;<br \/>\n}<\/p>\n<p><span style=\"color: #0000ff;\">public<\/span> String getMsg() {<br \/>\n<span style=\"color: #0000ff;\">return<\/span> msg;<br \/>\n}<\/p>\n<p><span style=\"color: #0000ff;\">public<\/span> <span style=\"color: #0000ff;\">void<\/span> outInfo() {<br \/>\nSystem.out.println(<span style=\"color: #800000;\">&#8220;\u8fd9\u662f\u6d4b\u8bd5Java\u53cd\u5c04\u7684\u6d4b\u8bd5\u7c7b&#8221;<\/span>);<br \/>\n}<br \/>\n}<\/div>\n<\/div>\n<div>\u63a7\u5236\u53f0\u8f93\u51fa\u7ed3\u679c\uff1a<\/div>\n<div>\n<div>\u8fd9\u662f\u6d4b\u8bd5Java\u53cd\u5c04\u7684\u6d4b\u8bd5\u7c7b<br \/>\n\u91cd\u65b0\u8bbe\u7f6emsg\u4fe1\u606f\uff01<\/p>\n<p>Process finished with exit code 0<\/p><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u662f\u4e2a\u6d4b\u8bd5\u7528\u7684\u4f8b\u5b50\uff0c\u901a\u8fc7\u53cd\u5c04\u8c03\u7528\u5bf9\u8c61\u7684\u65b9\u6cd5\u3002 TestRef.java import java.lang.reflect.Method; import java.lang.reflect.InvocationTargetException; \/** * Created by IntelliJ IDEA. * File: TestRef.java * User: String * Date: 2010-3-29 14:48:44 *\/ public class TestRef { public static void main(String args[])\u00a0throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { Foo foo =\u00a0new Foo(&#8220;\u8fd9\u4e2a\u4e00\u4e2aFoo\u5bf9\u8c61\uff01&#8221;); Class clazz = foo.getClass(); Method m1 = clazz.getDeclaredMethod(&#8220;outInfo&#8221;); Method m2 = clazz.getDeclaredMethod(&#8220;setMsg&#8221;, String.class); Method m3 &hellip; <a href=\"https:\/\/www.strongd.net\/?p=585\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">\u901a\u8fc7\u53cd\u5c04\u8c03\u7528\u5bf9\u8c61\u7684\u65b9\u6cd5<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-585","post","type-post","status-publish","format-standard","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/585","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=585"}],"version-history":[{"count":1,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/585\/revisions"}],"predecessor-version":[{"id":586,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/585\/revisions\/586"}],"wp:attachment":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=585"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=585"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=585"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}