java - JetBrains' @Contract annotation -
how org.jetbrains.annotations.contract annotation work? how intellij idea support it?
first off, should annotation idea use check possible errors. java compiler ignore entirely (it'll in compiled artifact have no effect). having said that...
the goal of annotation describe contract method obey, helps idea catch problems in methods may call method. contract in question set of semi-colon separated clauses, each of describes input , output guaranteed happen. cause , effect separated ->, , describe case when provide x method, y always result. input described comma-separated list, describing case of multiple inputs.
possible inputs _ (any value), null, !null (not-null), false , true, , possible outputs adds fail list.
so example, null -> false means that, provided null input, false boolean result. null -> false; !null -> true expands on null always return false , non-null value always return true, etc. finally, null -> fail means method throw exception if pass null value.
for multiple-argument example, null, !null -> fail means that, in two-argument method, if first argument null , second not null, exception thrown, guaranteed.
if method not change state of object, returns new value, should set pure true.
Comments
Post a Comment