History of Java annotation

Summarize the role and history of Java annotations.

history

The "@" annotation is introduced in Java 1.5.

--It was born as a comment that gives a hint to the compiler, such as @Override.

Benefits of using annotations.

--Code accuracy: Annotations such as @ Nullable, @ Deprecated, and @Override can add important semantic information to methods and fields so that the compiler enforces that information. it can.

--Test Method: Until TestNG and annotations appeared, JUnit used reflection to determine that a method was a test method. This determination required a special naming convention.
The adoption of annotations eliminates the need to use naming conventions.

--Persistence (Hibernate, etc.): By adding annotations, fields and methods can be associated with data stored in the database.

--Dependency injection: You can annotate a class that needs to be injected to indicate that.

Frequently used annotations

@Nullable and @ Nonnull (javax.annotation)

--Can it be attached to field and method parameters and the variable can take a null value? Please specify. --This annotation is very useful and many tools that use the Java compiler (javac) (the major IDEs are typical examples) recognize these two. --Whenever possible, always use this annotation. You'll soon notice that the number of null pointer exceptions in your code base drops sharply.

@Override

Mandatory since Java6.

Reason

--This annotation must be added to all methods that override the methods of the parent interface or parent class. --This addition causes the method to be overridden unintentionally.

--On the contrary, you can prevent the situation where you think that you have "overridden" a method that was not overridden due to a typo.

Referenced article (Thank you always)

https://www.oracle.com/webfolder/technetwork/jp/javamagazine/Java-MA16-Annotations.pdf

Recommended Posts

History of Java annotation
[Java] Annotation
[Java] Creation of original annotation
[Java] Annotation
[Java] Overview of Java
Expired collection of java
Predicted Features of Java
[Java] Significance of serialVersionUID
NIO.2 review of java
Review of java Shilber
java --Unification of comments
JAVA learning history interface
java (merits of polymorphism)
NIO review of java
[Java] Three features of Java
Summary of Java support 2018
[In-house study session] Basics of Java annotation (2017/11/02) ~ Under construction ~
About an instance of java
[Java] Mirage-Basic usage of SQL
JAVA learning history interface inheritance
[Java] Beginner's understanding of Servlet-②
[Java] Practice of exception handling [Exception]
Java history in this world
[Java11] Stream Summary -Advantages of Stream-
[Java] Beginner's understanding of Servlet-①
Java end of month plusMonths
[Java] Summary of regular expressions
[Java] Summary of operators (operator)
[Java] Implementation of Faistel Network
[Java] Comparator of Collection class
Summary of Java language basics
[Java] Summary of for statements
Summary of Java Math class
Enumeration of all combinations Java
java (inheritance of is-a principle)
Implementation of gzip in java
Advantages and disadvantages of Java
Benefits of Java static method
[Java] Summary of control syntax
Implementation of tri-tree in Java
Summary of java error processing
[Java] Summary of design patterns
[Java] Summary of mathematical operations
[Java] Simplify the implementation of data history management with Reladomo
Think of a Java update strategy
[Java] Delete the elements of List
[For beginners] Summary of java constructor
Various methods of Java String class
Root cause of java framework bugs
About fastqc of Biocontainers and Java
[Java version] The story of serialization
Summary of [Java silver study] package
About Lambda, Stream, LocalDate of Java8
Read CSV in Java (Super CSV Annotation)
Story of passing Java Gold SE8
Sort a List of Java objects
[Java] Output by FormatStyle of DateTimeFormatter
[Java] Input to stdin of Process
About binding of Spring AOP Annotation
Basic usage of java Optional Part 1
Handling of time zones using Java