If the code is working, great. However, you may want to write
if(!property.equalsIgnoreCase("title") && !property.equalsIgnoreCase("author")) {}
There are two changes:
First, the if(! )
statements are combined into if(! && ! )
. That is simpler and avoids writing unnecessary statements.
Second, if(!"title".equalsIgnoreCase(property))
is changed to
if (!property.equalsIgnoreCase("title"))
Writing the variable left of the .
and the compared string as the parameter of equalsIgnoreCase()
is the more common notation; maybe it is a matter of preference and not of logic, though it could just as easily be a matter of practicality. Look into it, or just change it to the common notation to be safe. Intuitively, they seem the same:
your way: if (!variable == string)
common way: if (!string == variable)
*Note that for the purposes of this logicking,
== = .equals()
:)
That's amusingly redundant, so more clearly:
==
is the same as .equals()
Also note that
(== == .equals()) = false
:) in Java,
Namely that ==
, a boolean comparator, does not equal .equals()
, a string comparator utilizing boolean comparison. You can use ==
to compare strings, but .equals() is more powerful: as you have experienced, it can utilize more advanced comparison such as .equalsIgnoreCase()
.
With that background, the original logic can be put even more simply:
your way: if (!b == a){}
common way: if (!a == b){}
If you reduce it to these statements, the two notations appear equal.
All of that simply serves to say that you might want to rearrange your syntax; if you still get the error let us know.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…