RFR: 8289397: Fix warnings: Possible accidental assignment in place of a comparison. A condition expression should not be reduced to an assignment
Kevin Rushforth
kcr at openjdk.org
Tue Jul 26 22:35:12 UTC 2022
On Tue, 26 Jul 2022 21:14:58 GMT, Andy Goryachev <angorya at openjdk.org> wrote:
> - replaced with exact functional equivalent (in the presence of exceptions, for example)
It seems there is disagreement on the utility of doing this. I don't care as much about silencing the warning in Eclipse as I do about making it clear to a reader that the assignment was intended. For everything except boolean assignments, Java already provides that, since unlike C/C++, `if (ival = integerFunc(...))` will not compile. If you meant to do the assignment, as opposed to an equality test, you need to test the return value explicitly.
So the question we should ask for boolean vars, where Java is as prone to this confusion as C/C++: is using the same "test explicitly" pattern sufficient? And if not, would a comment help?
-------------
PR: https://git.openjdk.org/jfx/pull/851
More information about the openjfx-dev
mailing list