Why doesn't CharBuffer.put(String) take a CharSequence?

5 messages Options
Embed this post
Permalink
Gili

Why doesn't CharBuffer.put(String) take a CharSequence?

Reply Threaded More More options
Print post
Permalink
Hi,

I'm curious, why does http://java.sun.com/javase/6/docs/api/java/nio/CharBuffer.html#put(java.lang.String) take a String instead of a CharSequence?

Thank you,
Gili
Dane Foster

Re: Why doesn't CharBuffer.put(String) take a CharSequence?

Reply Threaded More More options
Print post
Permalink
Because String IS A CharSequence.

On Thu, Jun 25, 2009 at 11:35 AM, Gili<[hidden email]> wrote:

>
> Hi,
>
> I'm curious, why does
> http://java.sun.com/javase/6/docs/api/java/nio/CharBuffer.html#put(java.lang.String)
> take a String instead of a CharSequence?
>
> Thank you,
> Gili
> --
> View this message in context: http://n2.nabble.com/Why-doesn%27t-CharBuffer.put%28String%29-take-a-CharSequence--tp3155780p3155780.html
> Sent from the nio-discuss mailing list archive at Nabble.com.
>
>
Alan Bateman

Re: Why doesn't CharBuffer.put(String) take a CharSequence?

Reply Threaded More More options
Print post
Permalink
In reply to this post by Gili
Gili wrote:
> Hi,
>
> I'm curious, why does
> http://java.sun.com/javase/6/docs/api/java/nio/CharBuffer.html#put(java.lang.String)
> take a String instead of a CharSequence?
>
> Thank you,
> Gili
>  
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4860681
Gili

Re: Why doesn't CharBuffer.put(String) take a CharSequence?

Reply Threaded More More options
Print post
Permalink
Any chance you can roll this in as part of JDK7? :)

Right now my code has to use fragile "instanceof" code. It will break if new implementations are added in the future. I took a look at the underlying methods for put(CharBuffer) and put(String) and they seem to be doing the exact same thing, just using get() instead of chatAt().

Gili

Alan Bateman wrote:
Gili wrote:
> Hi,
>
> I'm curious, why does
> http://java.sun.com/javase/6/docs/api/java/nio/CharBuffer.html#put(java.lang.String)
> take a String instead of a CharSequence?
>
> Thank you,
> Gili
>  
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4860681
i30817

Re: Why doesn't CharBuffer.put(String) take a CharSequence?

Reply Threaded More More options
Print post
Permalink
Wouldn't it be nice if CharSequence had the getChars method of String?
I fear charAt makes algorithms that need buffered copies much slower.
I already asked why not, but adding methods is a incompatible change for interfaces. In this special case, if CharSequence was a abstract class, it could be easily be implemented by charAt, and overridden for performance in implementations, much like InputStream is now. In fact much the same thing could be said for sort in collections.
Missing abstract methods tend to be able to be implemented by primitive methods.
The reason i don't like to use interfaces (except enums that can't extend anything, and are very useful to discoverability).