This post originated from an RSS feed registered with Java Buzz
by dion.
Original Post: CharSequence: one of those quiet gems
Feed Title: techno.blog(Dion)
Feed URL: http://feeds.feedburner.com/dion
Feed Description: blogging about life the universe and everything tech
When is a String not a String?. Simon Harris has brought up the nice CharSequence interface that both Strings and StringBuffers implement.
This means that we can pass around the interface and let us give the implementation later.
Maybe it would be nice to have had 'String' be an interface itself, and when you coded: String foo = "bar" it would create an ImmutableString which implements String. Then we could come up with crazy implementations of String :)
However, we would run into a lot of security concerns, as people could sneak in BackdoorStringWhichEmailsMeYourPassword.
Anyway, CharSequence has been a very useful interface for me too, for those cases where I really do want to encapsulate multiple impls.