Java reflection part of the application

xiaoxiao2021-03-06  21

Import java.lang.reflect.InvocationTargeTexception; import java.lang.reflect.Method;

Public class test {

Public static void main (string [] args) {try {class clazz = class.Forname ("java.lang.stringbuffer"); object obj = clazz.newinstance (); class [] paramtypes = {string.class}; method MM = CLAZZ.GETDECLAREDMETHOD ("append", paramtypes); mm.invoke (obj, new object [] {"Hello, World"}; system.out.println (obj);} catch (classnotfoundexception e) {e. printStackTrace ();} catch (InstantiationException e) {e.printStackTrace ();} catch (IllegalAccessException e) {e.printStackTrace ();} catch (SecurityException e) {e.printStackTrace ();} catch (NoSuchMethodException e) { E.PrintStackTrace ();} catch (illegalargumentException e) {E.PrintStackTrace ();} catch (invocationtargetexception e) {E.PrintStackTrace ();}}}

转载请注明原文地址:https://www.9cbs.com/read-42961.html

New Post(0)