Getters/Setters: Yes, it is possible. The Project Lombok (07003) defines annotations for generating getters/setters and more.
So for example
06000
Will generate getter for name (not setter since it is final) and getter/setter for age. It will also generate equals, hashCode, toString and construtor initializing required fields (name). Adding @AllArgsConstructor would generate constructor initializing both fields.
There are other annotations and parameters giving you control over access rights (should your getter be protected or public), names (getName or name?), etc. And there is more. For example, I really like the extension methods.
Lombok is very easy to use. Just download the jar and use the annotations, then the getter/setters can be used in your code without actually being spelled out. Moreover, IDE’s like Netbeans support this, so that you see the getter/setter in code completion, navigation, etc. The annotations are used only during compilation not during runtime, so you don’t distribute lombok with your jar’s.
NotNull: This is supported by findbugs and IdeaJ IDE, maybe others
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/229177.html原文链接:https://javaforall.net
