Java specifies the reflection call of the basic parameter type
This article introduces the relevant knowledge of "java specifies the reflection call of the basic parameter type". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Import java.lang.reflect.InvocationTargetException;public class TestInvocation {public void getStr (String str) {System.out.println (str);} public void getStr (String str1,String str2) {System.out.println (str1); System.out.println (str2) } public static void main (String [] args) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {TestInvocation ti=TestInvocation.class.newInstance (); TestInvocation.class.getMethod ("getStr", String.class) .invoke (ti, "123") TestInvocation.class.getMethod ("getStr", new Class [] {String.class,String.class}) .invoke (ti, new Object [] {"123,456"});}} "reflection call of java specifying basic parameter type" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!