Skip to content

Instantly share code, notes, and snippets.

@tamtam180
Created March 29, 2012 06:30
Show Gist options
  • Save tamtam180/2234148 to your computer and use it in GitHub Desktop.
Save tamtam180/2234148 to your computer and use it in GitHub Desktop.
abstract class Base {
protected String aaa;
public Base setAaa(String aaa) {
this.aaa = aaa;
return this;
}
}
class Hoge extends Base {
protected String xxx;
public Hoge setXxx(String xxx) {
this.xxx = xxx;
return this;
}
}
new Hoge().setAaa("").setXxx("")
↑BaseのやつはChainできない..
どうやるのがスマートかなぁ・・
こうか?
abstract class Base <T extends Base<T>> {
protected String aaa;
public T setAaa(String aaa) {
this.aaa = aaa;
return (T) this;
}
}
class Hoge extends Base<Hoge> {
protected String xxx;
public Hoge setXxx(String xxx) {
this.xxx = xxx;
return this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment