The Javadoc gives this example for the matches
method:
assertThat(player).matches(p -> p.isRookie());
And indeed, when I define a dummy class Player, the above statement compiles ok. However, when I define a class that derives from Exception, then the following doesn't compile:
public class MyCustomException extends Exception {
public boolean isMyCustomFieldSet() { return true; }
}
...
MyCustomException myCustomException = new MyCustomExcpetion();
assertThat(myCustomException).matches(e -> e.isMyCustomFieldSet());
I can make it compile by using a cast:
assertThat(myCustomException).matches(e -> ((MyCustomException)e).isMyCustomFieldSet());
but that cast looks "ugly" and a bit of a hack to work around some sort of deficiency. Can I make it compile in a "nicer" way, i.e. without using a cast?