Java Reflection Instance

Source: Internet
Author: User

1  Packagecom.test;2 3 Importjava.io.IOException;4 ImportJava.io.InputStream;5 Importjava.lang.reflect.InvocationTargetException;6 ImportJava.lang.reflect.Method;7 Importjava.util.Properties;8  9  Public classTest {Ten   One     /** A      *  -      * @paramb parameter List -      * @parama the      * @return -      */ -      PublicString A (intBinta) { -String bb=b+2+ ""; + System.out.println (a); -System.out.println ("Through Inverse color"); +         returnBB; A     } at   -  -      Public Static voidMain (string[] args)throwsSecurityException, Nosuchmethodexception, IllegalArgumentException, Illegalaccessexception, invocationtargetexception { -          -         //read the configuration file to get the key value for the signature -InputStream InputStream =NewTest (). GetClass (). getClassLoader (). getResourceAsStream ("Log4j.properties"); inProperties p =NewProperties (); -         Try{ to p.load (inputstream); +}Catch(IOException E1) { - e1.printstacktrace (); the         } *String a = P.getproperty ("234234234");//string variable of method $Test test=NewTest ();Panax NotoginsengClass SS =int.class; -Class SA =int.class; theClass b[] =NewCLASS[2];//array of parameter types +          AB[0] = SS;//the type of the first parameter theB[1]= sa;//the type of the second parameter +Method get =Test.getclass (). GetMethod (A, b); -          $                                         //the class that invokes the method, the argument list $String AA = (string) get.invoke (test,NewInteger (3),NewInteger (3)); - System.out.println (AA); - } the  - Wuyi log4j.properties the  -  Wu234234234=a -  About  $  -  -  -  A     /** + * Read the properties file under the path to get the properties object the      * @paramPath -      * @returnProperties $      * @throwsIOException the      */ the      Public StaticProperties getProperties (String fileName)throwsioexception{ theString FilePath = Contentsmethod.class. GetResource ("/"). GetPath () +FileName; theFileInputStream in =NewFileInputStream (NewFile (FilePath)); -Properties p =NewProperties (); in p.load (in); theLogger.info ("contentsmethod.getproperties = load Config file" +FilePath); the         returnp; About}

Java Reflection Instance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.