Skip to main content
5 events
when toggle format what by license comment
Oct 22, 2017 at 19:02 vote accept Dioxin
Oct 22, 2017 at 18:21 comment added amon @VinceEmigh Yes, contains() could be a default method. If it existed it should not be implemented in terms of String#contains but the other way round: String should use the CharSequence implementation. The charAt() is different. It does not implement a search algorithm, it is a crucial part of the CharSequence: without it, the contents couldn't be copied into a different type like String. Streams are a crucial part of Java8, and adding these default methods is in line with additions to other interfaces like Collection.
Oct 22, 2017 at 18:09 comment added Dioxin You mention "This interface does not provide any string manipulation or searching methods. Those are out of scope.", but contains is not a mutation method, and there does exist searching methods (charAt), so how does this apply?. Also, "Because these are default methods, they do not impose additional requirements for classes implementing CharSequence." - Couldn't contains be implemented as a default via the impl return to String().contains(...), removing the requirement for classes to implement?
Oct 22, 2017 at 15:58 history edited amon CC BY-SA 3.0
clarified why subSequence is an instance method
Oct 22, 2017 at 15:50 history answered amon CC BY-SA 3.0