java.lang.Appendable_simple_demo

可追加(append)接口。实现了该接口的类的对象实例具有可向其追加字符或字符序列的能力。希望能够接收Formatter输出的类必须实现该接口。

package com.test;

import java.io.IOException;

public class JavaLangAppendAble implements Appendable
{
	StringBuilder str = new StringBuilder(0);
	
	@Override
	public Appendable append(char c) throws IOException
	{
		return str.append(c);
	}

	@Override
	public Appendable append(CharSequence csq, int start, int end)
			throws IOException
	{
		return str.append(csq,start,end);
	}

	@Override
	public Appendable append(CharSequence csq) throws IOException
	{
		return str.append(csq);
	}
	
	
	public static void main(String[] args) throws IOException
	{
		JavaLangAppendAble able = new JavaLangAppendAble();
		able.append("this is test");
		System.out.println(able.str.toString());
	}
}

 

 

你可能感兴趣的:(java,C++,c,C#)