Just looking at the annotations in Java and always saying that annotations introduce a Java bean, I'm going to ask, what is a Java bean?
By reference: https://www.zhihu.com/question/19773379 under Tiansheng's answer
The Java language lacks attributes, events, and multiple inheritance capabilities. So, if you want to implement some of the common requirements of object-oriented programming in Java programs, you can only write a lot of glue code. Java beans are the idiomatic pattern or convention for writing this set of glue code. These conventions include GetXXX, Setxxx, Isxxx, Addxxxlistener, Xxxevent, and so on. Classes that follow these conventions can be used in several tools or libraries.
For example, if someone wants to implement a one-way linked list class in Java, this might be the case:
// 编译成 java-int-list_1.0.jarpublic final class JavaIntList { static class Node { public Node next; public int value; } public Node head; public int size;}
In order to be able to quickly get the size of the list, the list size is cached in a size variable. Use the following:
JavaIntList myList = new JavaIntList();System.out.println(myList.size);
Javaintlist's author is very satisfied, so the open source of the Java-int-list Library version 1.0. The file name is Java-int-list_1.0.jar. After publishing, many users were attracted to use Java-int-list_1.0.jar.
One day, the author decides to save memory, do not cache the size variable, and change the code to this:
Compile into Java-int-list_2.0.jarPublicFinalClassJavaintlist{StaticFinalClassNode{PublicNodeNext;PublicIntValue;}PublicNodeheadpublic int getsize () {node n = headint i = 0while (n != null ) {n = n. Nexti++; } return i} /span>
Then released the 2.0 version: Java-int-list_2.0.jar. After the release, the original Java-int-list_1.0.jar users have upgraded the version to 2.0. As soon as these users upgraded, they found that their programs were all broken, saying they could not find any size variables. So these users put the author to beat a meal, no longer dare to use the Java-int-list library.
The story tells us that if you don't want to be beaten to death, you have to stay backwards compatible. The Sun company also knows this truth when designing the Java language. Therefore, in the Java standard library, there will never be a public int size code, and must be written in the beginning:
private int size;public int getSize() { return size; }
Let the user start with GetSize, so that when the GetSize implementation is modified one day, it does not break backwards compatibility. This public int getsize () {return size;} Is the Java Bean.
What is a Java Bean