I think the yoda style is usually a bad idea.
Java:
string.equals("literal"); // normal style
"literal" .equals (string); // yoda style
You should remember that we are talking about objects; thus, these two lines are semantically different. If string is null, the first line throws a NullPointerException while the second line evaluates to false. In "normal style" the second line is roughly equivalent to
Java:
string != null && string.equals("literal"); // short circuit evaluation
Sometimes this is
n't what you want to do. In many common scenarios you are (implicitly) asserting that the string is not null. For example, you might have something like
String string = getInstalledVersion();
to read the version number of a different program (eg, of your kernel) from a file and you really expect that string to be there . In this scenario, a null string would be something (you think!) impossible to happen and this is exactly the case where throwing an exception (something is going wrong) is exactly what you wanna do.
In a different scenario, let's say you have something like
String string = getLastVersion ();
to fetch the last version number of your own program from the network. In this case you already expect that the user might have no access to the internet sometimes, so getLastVersion () returns null when the website is unreachable. In this case, assuming evaluating to false if the string is null is exactly what you want to do, the yoda condition might save you to write an explicit test. Technically speaking the yoda condition is slightly faster than its "roughly equivalent" version in normal style even though, in practice, this performance difference hardly measurable (especially in a language like Java).Most importantly, even if you really want to squeeze every nanosecond out of your program,
Yoda conditions don't throw exceptions, but null is only seldomly considered to be a valid state for an object and clear is better than brief. The reason why null is only seldomly considered to be a valid state for an object is highlighted by the same guy who invented the null reference
PS. I answered you in English because I sensed that your message is a bit google translated
PS extension. OliWan talking about yoda conditions is a curious coincidence.
Not in java. In java strings must be compared through a method, otherwise go to compare if the two objects have the same reference (if they point to the same thing).