How is Java doc invariant for a class?

I want to know exactly where the comment should go, and which keyword should I use, since I really can’t find an example on the Internet, should I, for example, do this?

/**
 * @invariant invariant example
 */
 public class Example {
 } 
+4
source share
1 answer

There are several options

@ Contract annotations

Some examples

  • @Contract ("_, null → null") - the method returns null if its second argument is zero.

  • @Contract ("_, null → null; _ ,! null →! Null") - the method returns null if its second argument is null, and not null otherwise.

  • @Contract ( "true → fail" ) - assertFalse() , true .

. https://www.jetbrains.com/help/idea/2016.2/contract-annotations.html.

IntelliJ IDEA. . , .

. , .

, https://docs.oracle.com/javase/7/docs/api/java/util/Map.html#put(K,%20V)

, .

, . Map.put (, )

  • @throws UnsupportedOperationException, put           
    • @throws ClassCastException,        .
    • @throws NullPointerException, null       .
    • @throws IllegalArgumentException, -        .
+4

Source: https://habr.com/ru/post/1660234/


All Articles