another useful default method - Appendable#appendCodePoint

Remi Forax forax at univ-mlv.fr
Fri Dec 28 06:17:56 PST 2012


On 12/26/2012 11:56 PM, Per Bothner wrote:
> Not directly in Lambda's purview, but this seems like it would be
> a useful addition to Appendable - and another nice example of how
> default methods are helpful:
>
> package java.io;
> interface Appendable {
>       ...
>       public Appendable appendCodePoint(int c) throws IOException default {
>           if (c >= 0x10000) {
>               append((char) (((c - 0x10000) >> 10) + 0xD800));
>               c = (c & 0x3FF) + 0xDC00;
>           }
>           append((char) c);
>           return this;
>       }
> }

yes, good idea, playing with code points in Java is not always a pleasure.

BTW, default is now a modifier so it should be declared in front of the 
method, not at the end.

Rémi



More information about the lambda-dev mailing list