When using GCC to compile C or C ++, you can mark functions using the ((warn_unused_result)) attribute , which is why the compiler will complain if you call a function that returns something and then doesn't execute, assign it something- sometime.
I have some methods in the Java library that I am developing that have methods that call and then discard the result is always an error. I would like API users to be able to identify such errors through static analysis, for example using FindBugs or IntelliJ checks.
I am wondering if there is a method annotation that is commonly used to designate methods or functions as "should use the result." FindBugs has some special error finders for the standard library, but a general way would be helpful.
source share