Created
March 29, 2012 06:30
-
-
Save tamtam180/2234148 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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