- ★★Java質問・相談スレッド176★★ [無断転載禁止]©2ch.net
445 :デフォルトの名無しさん[sage]:2016/02/20(土) 15:52:34.57 ID:lX2SSkbU - class A extends Writer {
public void write(char[] cbuf, int off, int len){System.out.print(new String(cbuf,off,len));} public void close(){} public void flush(){} public A append(CharSequence csq)throws IOException{super.append(csq); return this;} A indent(){return this;} A unIndent(){return this;} } class B extends A { B footer(){return this;} } B b = new B(); b.indent().append("aaa").unIndent(); b.footer(); //コンパイルエラー new B().indent().append("aaa").unIndent().footer(); こういうのがあればいいんだけど ThisT indent(){return this;} 親のreturn this系メソッド全部オーバーライドするしかないですかね?
|