CodePudding user response:
Private property, and other modules in the code cannot be directly read this property, but to read again, the get method is used to provide read interfaceCodePudding user response:
Is essentially no difference, but the getXXX JavaBean specification, recognized at home and abroad, we consciously abide by the specification, many frameworks, jars, are to be carried out according to the specification,For example:
fastJson package, will be a JSON string with Java objects, when the Java object into a JSON string because properties are private and cannot be directly obtained, package will be through reflection, automatically all the getXXX method invocation object, get the attribute value, then the attribute set into a JSON string xXX, in other words, even if you don't have a defined xXX properties, but with getXXX methods in your class, generated a JSON string field, also can have xXX
So also in the same way: the JSP page, write in your JSP page xXX variables, transformed in the JSP invoked when the getXXX methods, regardless of whether there are in your class xXX method,
and MyBatis, Hibernate framework, based on the configuration class Y name is xXX, the mapping objects through reflection instantiate a Y, then through setXXX will result in the object,
If you don't write getXXX/setXXX classes defined, the application of these abnormal results,
you must, of course, through other methods and members of the assignment is right, you said these frameworks, I don't use their Jar package, I have to write their own or secondary development can also,
But everyone abide by such specification, it is not necessary to make special, oneself a person when writing test code, it's nothing, but after entering the company a lot of large projects, everyone to do this, you a person to affecting the efficiency, but also inconvenient may also have a bug, it is no good,