I have encountered the following strange behavior in Java using jdk 13.0:
String foo = "Something";
String bar = "Other";
if (foo.equals(bar));
{
System.out.println("Face palm");
}
Sadly, the above comparison succeeds and the "Face palm" is printed out. What causes this behavior is the existence of the semi-colon in the end of the if statement.
The correct way of doing this is:
String foo = "Something";
String bar = "Other";
if (foo.equals(bar))
{
System.out.println("Face palm");
}
Could anyone explain why Java behaves like this ?
Could that be just an uncaught syntax error by the compiler ?