What are generics used for in Java

Even the pen owner has not understood the concept of reflection for a long time, suddenly a flash of light that understands a little, as if it could help everyone

First we create a person class

Create another test class

Operating profit

 

That is reflection. . .

 

You may be wondering what this is good for

General business development, we seldom use reflection

1. The advantages of reflection are: Can confirm objects and methods at runtime。

2. The following is a simple example of the reflection application scenario:

If a game has a configuration file, a renderType in the configuration file determines which RenderHandler should be called when the game starts rendering the game.

(RenderHandler: An interface, there is a rendering method, HighRenderHandler, LowRenderHandler, MiddleRenderHandler and a total of 10 implementation classes.)

When the game starts you will need to get a RenderHandler to render the game. Now there are two possibilities: One possibility is to use the switch to judge

 

The other is to use reflection:

 

3. The switch uses 14 lines of code and the reflection only uses 2 lines of code. In reality, you may not see such a stupid example, but it helps to understand the reflection.

 

 

Reference link

https://www.cnblogs.com/2333/p/5852969.html