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.
Leave a Reply
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.