annotations - How to mark a Java method as "must use result" for static analysis purposes? -


when using gcc compile c or c++, can mark functions attribute((warn_unused_result)) cause compiler complain if invoke function returns , don't assign anything.

i have methods in java library develop have methods - calling them , throwing away result bug. api users able identify such bugs via static analysis, such findbugs or intellij inspections.

i wondering if there method annotation commonly used mark methods or functions "must use result". findbugs has special case bug-finders standard library, general way useful.

there totally standard annotation this, , @checkreturnvalue. findbugs has it; see e.g. here.

guava uses internally -- e.g. in configuration methods splitter -- jsr 305.


Comments