if (someString != null && map.containsKey(someString = someString.toLowerCase()))
I am wondering if this would be considered a good or a bad way to assign my string value. I believe I am doubling the use of the null check by writing the code this way?
The only problem I can see there is if you mistakenly got
==instead of=, it will be a boolean value, and can give you unexpected result, because it will not show youCompiler Error, and the condition will never get true.Map.containsKeywill always returnfalse–No Compiler Error, NoRuntime Exception, justfalseresult everytime, and it would make your life hell searching for the issue: –Ideally, you should avoid using it like that. The code is less readable when you assign it that way. Also, it is not guaranteed that you don’t do any
typing mistake. So, better to avoid using it that way.