Links 3.29

I am a huge fan of [[Diigo:!

– [[[JavaSpecialists 123] – Strategy Pattern with Generics:

昨日、スパークリングワインを飲みつつ Generics の使い方について悩んでいたのだけど、氷解したような気がする。getDetailedType を書くしかないので。Wadler のお墨付きがあるので安心できます。




<div><div>Inside TaxPayer, we want to use the derived class P directly in the extortCash() method. However, the only way of getting an instance without compiler warnings is to pass it in from the subclass. We can solve this issue with a factory method called <code>getDetailedType()</code> that returns the subclass.</div></div>



<div><div>The beauty of using generics here is that EmployeeTaxStrategy does not need to downcast anymore.</div></div>




<a href="; rel="tag">java</a>

<a href="; rel="tag">tutorial</a>