Java 3 annotations and reflection interview preparation

Java annotations

jdk currently provides three annotations @Override, @Deprecated, @SuppressWarnnings

①@Override: used to identify the method, to identify that the method belongs to the method of overriding the parent class

②@Deprecated: Used to identify a method or class. It is recommended not to use it to identify that the class or method is out of date.

③@SuppressWarnnings: Used to selectively turn off the compiler warnings for classes, methods, member variables, and variable initialization

Meta annotation annotation of custom annotation

Java reflection mechanism

JAVA reflection mechanism is in the running state, for any class, you can know all the properties and methods of this class; for any object, you can call any of its methods and properties; this kind of dynamically acquired information and dynamic calls The function of the method of the object is called the reflection mechanism of the java language.

Three kinds of class names acquired by reflection mode:
① class name .class
② object name .getClass ();
③Class.forName (package name class name.)

Function:
Simply put: ①Get the
class name getClass() ②Get the
method getMethods() single getMethod(name)
③Get the constructor getConstructors() ④Call the
method invoke(c.newInstance())

Java blog post is very good-Portal

Guess you like

Origin blog.csdn.net/BOWWOB/article/details/113706662