JDK1.8源码学习--lang包(Appendable)

本文介绍了Appendable接口,它是用于接收格式化输出的接口,包括append方法用于追加字符序列。文章强调了学习的过程,从无知到吸收知识再到输出内容,并提醒读者注重知识的积累和提炼。同时,源码注释中提到线程安全和错误处理的责任在于实现该接口的类。
摘要由CSDN通过智能技术生成

前言


月是一轮明镜,晶莹剔透,代表着一张白纸(啥也不懂)

央是一片海洋,海乃百川,代表着一块海绵(吸纳万物)

泽是一柄利剑,千锤百炼,代表着千百锤炼(输入输出)

月央泽,学习的一种过程,从白纸->吸收各种知识->不断输入输出变成自己的内容

希望大家一起坚持这个过程,也同样希望大家最终都能从零到零,把知识从薄变厚,再由厚变薄!
 

/**
 * An object to which <tt>char</tt> sequences and values can be appended.  The
 * <tt>Appendable</tt> interface must be implemented by any class whose
 * instances are intended to receive formatted output from a {@link
 * java.util.Formatter}.
 *
 * <p> The characters to be appended should be valid Unicode characters as
 * described in <a href="Character.html#unicode">Unicode Character
 * Representation</a>.  Note that supplementary characters may be composed of
 * multiple 16-bit <tt>char</tt> values.
 *
 * <p> Appendables are not necessarily safe for multithreaded access.  Thread
 * safety is the responsibility of classes that extend and implement this
 * interface.
 *
 * <p> Since this interface may be implemented by existing classes
 * with different styles of error handling there is no guarantee that
 * errors will be propagated to the invoker.
 *
 * @since 1.5
 */

        根据源码注释我们可以知道:

  • 实现该接口的类是为了添加字符序列和值
  • 如果某个类的实例打算接收Formatter的格式化输出,那么必须实现该接口
  • 实现该接口之后,对于多线程的时候,会导致线程安全问题
  • 如果这个接口必须实现,那么无法保证一些错误的方式会传递给调用者      

 二.Appendable接口的方法:


    /**
     *  添加字符序列到尾部
     */
    Appendable append(CharSequence csq) throws IOException;


    /**
     * 添加指定字符序列的子序列
  
     */
    Appendable append(CharSequence csq, int start, int end) throws IOException;

    /**
     * Appends the specified character to this <tt>Appendable</tt>.
     *添加字符到尾部
 
     */
    Appendable append(char c) throws IOException;

                很简单的三个方法.

四.总结

        月央泽,继续加油!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值