Java does not understand the bite - reflex

The relationship between files and Java .class file

All the contents of the file which contains the Java code: classes, interfaces, member variables, member method ==>

.class bytecode problem: .Java file generated by the compiler tool Javac corresponding .class bytecode files, using decompiler provided in the JDK, the class can be seen that the .class file that contains the full class name of the package.

Filed member variables, data types and names of members of the member variables variables [If reference data types, but also the full package name. Class name]

Method member method, method permissions modifier, return type, class name, the formal parameter list

to sum up

.class bytecode file contains all the contents of Java files.

Relations program loading process and .class files

Then the process of running a Java file, which is currently involved in a class-code program needs to perform, you need to load the .class bytecode files of this class, when the .class bytecode files loaded stage of the procedure, in memory of [area Code]

.class file is loaded into byte code [code area] memory ,. class file contains the Java program corresponding to all the contents, i.e., in the presence of a code region of space, there is a .class file that contains all the Java programs content

Everything in Java objects

Java code, the area code stored in memory .class byte code memory space, as an object which contains all the object corresponding to the content files Java

The method used must be reflected [key]

class method involves:

Class.forName (String packageNameAndClassName); Return Value is the class type

Static member method of class Class, by the full package name, class name to obtain the Class object corresponding .class files, but also the way to .class file loaded.

Class name .class return value type class

.Class method by class name, obtaining the corresponding class class object, method of the type commonly used for the parameter

Class object, getClass ();

Obtaining the corresponding .class Class class object through the class object, method parameters, or data type determination.

Constructor class constructor method involves

getConstructors (); Return Value Type the Constructor is a [] array

Get the current Class Java class object corresponding to the file all the object array class constructor public modified

getDeclaredConstructors (); violence reflected

Get the current Class Java class object corresponding to the file, the class object [] array constructor method of all, including the privatization of the constructor

public Constructor getConstructor(Class... initArgumentTypes);   

The specified data type had to select the corresponding construction method, this may throw exceptions; one and only acquire the data type specified in the class of non-privatization constructor class object

Abnormal: NoSuchMethodException

Class: Ray-based constraint data, the parameter type currently required method

eg: need of type int int.class; String type String.class

...: variable length parameter

Parameter Type constructor takes a number of parameters may not have, it is possible to have a variable length parameter ... class constraint parameters used to enhance universal code

eg: no parameters () or (null);

Parameter Type Type int (int.class)

initArgumentTypes:

Parameter name, type complex initialization parameters

public Constructor getDeclaredConstructor(Class... initArgumentTypes);  【暴力反射】

Gets the parameter type of privatization and privatization Constructors Constructors

Is reflected from the code block of memory space occupied by the definition of the class is considered as a Class object, removed from something useful to show

Object newInstance(object... initArgument);

Constructor object to call through, passing the current constructor initialization parameters needed to create an object, create an object.

Object: Object class is a Java base class for all classes, where parameters of any type can be passed

...: variable length parameter, because Constructor class objects in the process of obtaining the constraint of the number of parameter uncertainty,

Method member method involves methods

Method[] getMethods();

Gets the members of the public methods within the class of all modifications, including public modification methods inherited from the parent class comes.

Method [] getDeclaredMethods (); violence reflected

All members of the method in obtaining class, but excludes inherited from the parent class's method from

Method[] getMethods(String methodName , Class ... paramterTypes);

The specific method name and parameters of the corresponding type, a corresponding modification of the public member methods

methodName :

Method name, specify a method which is acquired

paramterTypes:

Class used to constrain the use of your current parameter data type

...: variable length parameters, the number of parameters of the method, the order, there is no reference parameters problem

eg:cls.getMethod("setName" , String class);

Method[] getDeclaredMethods(String methodName , Class ... paramterTypes);

According to the specified method name and the corresponding parameter type, a corresponding modification of the public member methods, including privatization member methods, but excludes inherited from the parent class's method from

methodName :

Method name, specify a method which is acquired

paramterTypes:

Class used to constrain the use of your current parameter data type

...: variable length parameters, the number of parameters of the method, the order, there is no reference parameters problem

Object invoke(Object obj , Object ... arguments);

Method class invoked by the object, performs the corresponding method, parameters required

Executor execution of the current method: obj

arguments: Object ... variable length parameters, the current method performs the actual parameters needed

Field member variables related to the method

Field[] getFields();

Get all public member variable modified within the class

Field[] getDeclaredFields();

All members of the get class variables, including privatization member method

Field getField(String fieldName);

Gets the specified variable name member variable objects, modified requirements are public member variables

Field getDeclaredField(String fieldName);

Gets the specified variable name member variable objects, including private member variable privatization modified

set(Object obj , Object value);

First Object: data member variable settings specified in the corresponding caller

obj: caller

value: the current contents of the corresponding member variables required assignment

Object get(Object obj);

Gets the specified caller

Giving violent content reflecting the privatization of permission to operate

setAccessible(boolean flag);

Give Constructor, Method, Field objects, privatization of content, operating permissions, true representation can be operated

 

 

 

 

 

 

 

 

 

Published 13 original articles · won praise 27 · views 9353

Guess you like

Origin blog.csdn.net/weixin_42597414/article/details/104668634