Due to the inherent complexity, flow analysis is best performed in small chunks. Analyzing one method at a time can be done with good tool performance - whereas whole-system analysis is out of scope for the Eclipse Java compiler. The advantage is: analysis is fast and can be done incrementally such that the compiler can warn you directly as you type. The down-side: the analysis can not "see" which values (null or non-null) are flowing between methods (as parameters and return values).
This is where null annotations come into play. By specifying a method parameter as @NonNull
you can tell the compiler that you don't want a null value in this position.
Reference
Reference 2
Usage:
This link explains what annotation to use where.
Usage 2
Getters/Setters
: Yes, it is possible. The Project Lombok (http://projectlombok.org/index.html) defines annotations for generating getters/setters and more.
So for example
@lombok.Data;
public class Person {
private final String name;
private int age;
}
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
Reference 3