Matcher
implements MatchResult
, which "contains query methods used to determine the results of a match against a regular expression." Surprisingly, although group()
, group(int)
and groupCount()
are available through the MatchResult
interface, group(String)
is not.
Is this an oversight, or was it left out Java 7 for compatibility reasons? If it's for backwards compatibility, couldn't that have been resolved with a default method in Java 8?
This is because MatchResult
interface has been added with Java 1.5, while group(String)
is a Java 1.7 addition.
Adding group(String)
to the interface would have been a breaking change, because any other implementation outside of Java's Matcher
would not compile. Java designers generally avoid interface changes like that, so they did not do it.
A more interesting question is why they have not done it in Java 1.8, which allows specifying default implementations for interfaces. My guess is that there is no good default for such implementation, apart from throwing a "not implemented" exception.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With