s instanceof String
, s.matches(".*")
.static void tf002(String s) { if (s instanceof String) { assert s.matches(".*"); } }
FALSE! From the
Pattern
API:The regular expression.
matches any character except a line terminator unless theDOTALL
flag is specified.
tf002("\n"); // throws AssertionErrorThe correct statement is that for all
s instanceof String
, s.matches("(?s).*")
. Note that (?s)
is the embedded flag expression for Pattern.DOTALL
.Interestingly, Bug# 6565414 requests that
.*
be optimized since it "is always going to be true". The above counterproof demonstrates that this is incorrect: it's only trivially true in the so-called "single-line" mode.
No comments:
Post a Comment