I am trying to learn how to develop start-up apps fastly by using libraries and annotations. I have already experinced @NonNull, @Nullable ones.
While reading javadocs i noticed there is a @Contract annotation which has usage @Contract("null->fail") that makes compilation error if null passed.
Thats really cool feature but i cant use it because there is no annotation class in support.annotations package.
How can i get this feature? Or which library to import?
Thanks.
The @Contract annotation is used for defining a contract that a method must meet. This lets the IDE find problems in methods which call methods that you have annotated. You can use this annotation not only for annotating your own code but also for other existing libraries.
Contract annotations let you define expected outputs for given inputs, or put in other words, define dependencies between reference type and boolean arguments of a function and its return value. The mechanism of contract annotations allows creating APIs that could be consumed in easier and safer way.
JetBrains. Annotations help reduce false positive warnings, explicitly declare purity and nullability in your code, deal with implicit usages of members, support special semantics of APIs in ASP.NET and XAML frameworks and otherwise increase accuracy of JetBrains Rider and ReSharper code inspections.
You need to add jetbrains' annotations jar
to your classpath. You can find it in maven central or locally, in <IntelliJ IDEA Home>/lib/annotations.jar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With