たとえば、カスタムコンポーネントは、タイトルとしてどの文字列を描画するかを知っている必要があります。
オーバーライド
CustomComponent c = new CustomComponent(){
@Override
public String getTitle(){
return "A given title";
}
};
田畑
CustomComponent c = new CustomComponent()
c.setTitle("A given title");
最初のメソッドを使用すると、CustomComponentでStringフィールドを作成する必要はありませんが、コードははるかにクリーンです。強く推奨される/提案される方法はありますか?もしそうなら、なぜですか?
これは単なる例であることに注意してください。
ありがとう