Dark Horse programmer-java Basics-Reflex

Source: Internet
Author: User
Tags array length

An instance of the Java.lang.Class class represents a. class document that is loaded when the Java application runs.     Its constructor: Private Class () {} indicates that we cannot create a class object, the class object is automatically generated by the JVM, and each. Class document is loaded, and the JVM automatically generates the corresponding class object. When to load. class files into memory 1, with Class.forName () or ClassLoader (class Claz = Fu.class do not execute static{} blocks?? 2, note when creating objects with new:declaring a reference name with a class does not load the. class file (String str; does not load), only checks that the corresponding. class document exists, and the class is loaded only when you build the object with new。    forname (String name) method         where name is the full class name of a class that loads the. class file of the class into memory and creates the corresponding class object      class Common methods     getfield (): Returns fields of type public     Getdeclaredfield (): Returns fields of any type (including private)      GetMethod (String name,class<?> ... parameter)     Getdeclaredmethod (String name,class<?> ... parameter)      GetConstructor (class<?> ... params)     Getdeclaredconstructor (class<?> ... params)  field: Represents a field in Class     field common methods         GetName ()   return field name         GetType ()   Return class object of Claim type   &NBSP ;     isaccessible (): Determine if the field can be accessed         setaccessible (): Make it accessible         method: Represents a member method in a class         Getreturntype ()   Returns the Method object that represents the return type of the object         Object invoke (Object,object ... paras)           &NBSp If the underlying method is static, you can omit the specified   objParameters.            The parameter can be null. If the shape parameter required by the underlying method is 0, the provided argsThe array length can be 0 or null. Constructor: Represents the construction method of a class newinstance (Object ... params): About getResourceAsStream () A class loader can load a. class file, which of course can also load other files in the CLASSPATH environment, since it has so much power that it has no reason not to provide such a method in passing. It can also load only those files in the CLASSPATH environment.Note: When you use the class loader directly, you cannot/head. to load a file under a package:

InputStream ips = ReflectTest2.class.getClassLoader (). getResourceAsStream ("cn/itcast/javaenhance/ Config.properties ");

Load file for bin root path

InputStream ips = ReflectTest2.class.getClassLoader (). getResourceAsStream ("config.properties");

class provides a convenient way to load a file in the same package directory with the same classloader that loads the current class

InputStream ips = ReflectTest2.class.getResourceAsStream ("config.properties");

Load file for bin root path

InputStream ips = ReflectTest2.class.getResourceAsStream ("/config.properties");

On the problem of using reflection to perform the main function

public static void Main (string[] args, you can see that the parameters of the main function are the Invoke method in the Array method class: jdk1.5 Invoke (Name,object ... param     s) jdk1.4 invoke (name,object[] params) If you pass in an array in invoke, the first element of the array corresponds to strirng[] AGRs. It can be written like this: Invoke (name,new object[]{new string[]{"xxx"});

Dark Horse programmer-java Basics-Reflex

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.