I have found a strange behavior of assertions in Java (Eclipse). Easy example: If i execute this...
public static void main (String[] args) {
assert(getA() == "a") : "Invalid";
System.out.println("Assertion successful!");
}
private static String getA()
{
return "a";
}
... it will show me "Assertion successful!" as it should. However if i try this...
public static void main (String[] args) {
assert(getA() + "b" == "ab") : "Invalid";
System.out.println("Assertion successful!");
}
private static String getA()
{
return "a";
}
... I get an AssertionError. How come this Assertion doesn't return true?
Note:
- Don't forget to add the "-ea" Parameter in the VM arguments when testing! (Eclipse: enable assertions)