Before we say inline functions, let's talk about the procedure of calling the function.
call a function to actually transfer the execution order of the program to an address in memory where the function is held, and then return to  &NBSP when the program contents of the function are executed;
Go to the place before executing the function. This transfer operation requires to protect the site before the transfer and memory of the address of the execution, back to the scene first, and according to the original the
storage address continues to execute. This is usually called the stack and the stack. Therefore, function calls have a certain amount of time and space overhead. So for those function body
Code is not very large, and frequently called functions, this time and space consumption will be very large.  &NBSP
How to solve this problem of performance consumption, this time need to introduce an inline function. The inline function is the compiler that appears in the program at the time of program compilation, and the call expression for the inline function of the
is replaced directly by the function body of the inline function ( ). Obviously, this does not cause a reversal problem, but because the code in the body of the function is replaced in the program when the  &NBSP is compiled, the code of the target program is increased to increase the space overhead, which is not when the function is called on the time consignment;
So large, it can be seen that it is at the expense of increasing the target code in exchange for time savings.
When we learn to write C code at university, we learn to define some short logic in a macro. The advantage of this is that the compiler will use  &NBSP when compiling the compiler, and the
is replaced with the macro's code where the macro is. This eliminates the need to press the stack, the stack, and the arguments like the calling method. Improved performance. The of the inline function;
is treated like a macro, but unlike a macro, an inline function has its own characteristics (type, scope, and so on)
written C + + The code should know that in C + + there is an inline function, which is decorated with the inline keyword. In addition, functions written within the class definition are the
compiler is considered an inline function.
So what does an inline function look like in Java? Use the final keyword in Java to indicate that a function is an inline function, for example:
Java code
- Public final void Method1 () {
- TODO something
- }
This instruction is not required. The final keyword simply tells the compiler to consider performance improvements at compile time, and you can think of the final function as an inline function.
But what the compiler will do with it, the compiler will parse the performance comparison of processing the final function inline and not processing it inline.
Java inline functions